Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Vertical callback or per pixel callback : I understand/How does Tilengine work?
#11
(08-27-2023, 03:10 AM)megamarc Wrote: Hi!

I want to apologize if I sounded rude for not providing support on other languages, but that's the truth. I know that Nim transpiles to C (and Javascript), but I don't know about its architecture or optimizations. So I can't really tell which construct is more performant. As a general rule is good strategy to avoid conditionals as much as possible, and replace them with sequentials, or function pointers. Tilengine makes extensive use of function pointers, and I thought about adding some more on critical places that should increase performance.

For example replace this:

Code:
loop while condition:
  if a:
    do_treatment_a()
  else:
    do_treatment_b()

with this:

Code:
if a:
  loop while condition:
    do_treatment_a()
else:
  loop while condition:
    do_treatment_b()

Yes, I've fixed the initial black screen in non-vsync mode. I have yet to upload the builds to itch.io, but you can do a pull from GitHub and build it from sources. Let me know if it gets fixed for you.

You cannot enable scaling and affine on the same layer, as it can only have one state at a given time. The new mode just replaces the old one.

Feature accepted about getting the number of entries on a palette :-) this number is already available internally, just need to add a public function to retrieve it.

Hi!
You were not rude at all, I totally understand. We can't know everything about everything. I just had the idea "Hey what if I try to do something similar to Tilengine? It probably would be a good experience and I probably can learn a lot of things!"

That makes sense for the fact that one layer can have one mode at a time.

Thanks for accepting the feature idea! I do some improvements to the Nim bindings for Tilengine and I thought it was a necessary feature to avoid out of bounds errors.

I will compile the latest commit and tell you if it works.

I'm also working on a game for my final school work now. And guess what I'm using for graphics? Tilengine!
Reply
#12
Hi!

I've updated Tilengine binaries at itch.io. In addition to the initial black screen fix, I've implemented TLN_GetPaletteNumColors() following your suggestion. I understand the Nim binding may need this number, but if you passed a color index greater than available to a given palette function, it would fail setting TLN_ERR_IDX_PALETTE global error without crashing.

Cool to know you're going to use Tilengine in your school project! What are you stidying? What kind of game prototype are you planning to build?
Reply
#13
(08-29-2023, 09:41 PM)megamarc Wrote: Hi!

I've updated Tilengine binaries at itch.io. In addition to the initial black screen fix, I've implemented TLN_GetPaletteNumColors() following your suggestion. I understand the Nim binding may need this number, but if you passed a color index greater than available to a given palette function, it would fail setting TLN_ERR_IDX_PALETTE global error without crashing.

Cool to know you're going to use Tilengine in your school project! What are you stidying? What kind of game prototype are you planning to build?

Hi! Thanks for the update! I will try this!
I study programming and I'm working on an online multiplayer Shoot 'Em Up right now. Sometimes it's fun, sometimes it's pain. It's quite painful for now because in title screen and lobby, I use Layer 1 and 2, and in a level I don't use Layer 2. At each room initialization (including title screen and lobby) I clean all the tilemaps with a NULL check to avoid a double free, however, when I don't use this Layer 2, I have a segfault unless I remove the code that cleans tilemap (BAD PRACTICE! LEADS TO MEMORY LEAKS!)

Is there a manipulation I need to do before cleaning tilemaps? Especially when I don't use a layer? Thanks for your answer!

Edit : it often happens when I go to fullscreen mode.
Reply
#14
Hi,

As a general rule, there are two things to take into account when dealing with resources:

1. Don't delete a resource you don't own.

You own a resource when you explicitly create, load or clone it. You don't own a resource that has been chain-loaded and is a child of another resource. You should not do this:

Code:
TLN_Tilemap tilemap = TLN_LoadTilemap("tilemap.tmx", NULL); // load tilemap, you own it
TLN_Tileset tileset = TLN_GetTilemapTileset(tilemap); // gets chain-loaded tileset, you don't own it
TLN_DeleteTileset(tileset); // wrong! you don't own the tileset

2. Don't delete a resource that is currently assigned to the renderer.

Also applies to child resources, when you delete an owned resource, all of its owned child resources get deleted with it

Code:
TLN_Tileset tileset = TLN_LoadTileset("tileset.tsx"); // loads tileset
TLN_Palette palette = TLN_GetTilesetPalette(tileset); // gets palette of tileset
TLN_SetLayerPalette(0, palette); // assigns child palette to layer renderer
TLN_DeleteTileset(tileset); // wrong! tileset's palette is still atached to layer 0 but gets destroyed
Reply
#15
(08-30-2023, 06:18 PM)megamarc Wrote: Hi,

As a general rule, there are two things to take into account when dealing with resources:

1. Don't delete a resource you don't own.

You own a resource when you explicitly create, load or clone it. You don't own a resource that has been chain-loaded and is a child of another resource. You should not do this:

Code:
TLN_Tilemap tilemap = TLN_LoadTilemap("tilemap.tmx", NULL); // load tilemap, you own it
TLN_Tileset tileset = TLN_GetTilemapTileset(tilemap); // gets chain-loaded tileset, you don't own it
TLN_DeleteTileset(tileset); // wrong! you don't own the tileset

2. Don't delete a resource that is currently assigned to the renderer.

Also applies to child resources, when you delete an owned resource, all of its owned child resources get deleted with it

Code:
TLN_Tileset tileset = TLN_LoadTileset("tileset.tsx"); // loads tileset
TLN_Palette palette = TLN_GetTilesetPalette(tileset); // gets palette of tileset
TLN_SetLayerPalette(0, palette); // assigns child palette to layer renderer
TLN_DeleteTileset(tileset); // wrong! tileset's palette is still atached to layer 0 but gets destroyed

Hi!
Makes sense!
Now I only delete tilemaps from layers, I don't touch their tilesets nor their palettes and so on.
so I just can do 

TLN_Tilemap tilemap = TLN_GetLayerTilemap(myLayer);
TLN_DeleteTilemap(tilemap);
tilemap = NULL;

?
Reply
#16
Hi!
You can do this as long as you first call:

Code:
TLN_DisableLayer(myLayer)

If not, you'll be deleting a resource that is attached to an active layer, that will cause a segfault on the next render.
Reply
#17
(08-30-2023, 08:53 PM)megamarc Wrote: Hi!
You can do this as long as you first call:

Code:
TLN_DisableLayer(myLayer)

If not, you'll be deleting a resource that is attached to an active layer, that will cause a segfault on the next render.

I do that before deleting its tilemap. It works flawlessly... Until I go to fullscreen mode
Reply
#18
Hi,

To debug this particular issue I should have acces to full project (code with assets). You can send it via PM if you want
Reply
#19
(08-31-2023, 07:09 PM)megamarc Wrote: Hi,

To debug this particular issue I should have acces to full project (code with assets). You can send it via PM if you want

Is it a problem if the code is written in Nim?
Reply
#20
Unfortunately yes, I can only give support for Tilengine itself, not for other bindings. But I can take a look, maybe I can see something suspicious
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)