Different template mechanism

This commit is contained in:
2025-06-06 15:36:39 +02:00
parent 4652a83218
commit cac829ae17
3 changed files with 12 additions and 9 deletions
+2 -4
View File
@@ -256,8 +256,7 @@ chunkman_generate_Chunk_at (int cx, int cz)
if (rand() % 100 < 2)
{
Entity *tree = malloc (sizeof (Entity));
*tree = ETEMPLGET ("tree");
Entity *tree = ent_templates_clone ("tree");
tree->position[0] = x + xoffset;
tree->position[1] = chunk->heightmap [INDEX (x, z)];
tree->position[2] = z + zoffset;
@@ -268,8 +267,7 @@ chunkman_generate_Chunk_at (int cx, int cz)
if (rand() % 100 < 10)
{
Entity *grass = malloc (sizeof (Entity));
*grass = ETEMPLGET ("grass");
Entity *grass = ent_templates_clone ("grass");
grass->position[0] = x + xoffset;
grass->position[1] = chunk->heightmap [INDEX (x, z)];
grass->position[2] = z + zoffset;
+8 -2
View File
@@ -8,10 +8,16 @@ ent_templates_add (char *key, Entity *entity)
g_hash_table_insert (templates, key, entity);
}
Entity
Entity *
ent_templates_get (char *key)
{
return *(Entity *) g_hash_table_lookup (templates, key);
return (Entity *) g_hash_table_lookup (templates, key);
}
Entity *
ent_templates_clone (char *key)
{
return g_memdup2 (ent_templates_get (key), sizeof (Entity));
}
void
+2 -3
View File
@@ -8,7 +8,6 @@
#include "entity.h"
#include "../resources.h"
#define ETEMPLGET(key) (ent_templates_get (key))
void ent_templates_init ();
Entity ent_templates_get (char *key);
Entity *ent_templates_clone (char *key);
Entity *ent_templates_get (char *key);