Commit 38f62206 authored by Vivien Kraus's avatar Vivien Kraus
Browse files

Get rid of the in-place construction of TarotSolo

parent 7325f59c
Pipeline #203250 failed with stages
in 30 minutes and 49 seconds
......@@ -2342,13 +2342,6 @@ A game, where all players but the specific dealt player play using the
AI.
#+end_deftp
#+attr_texinfo: :options {size_t} tarot_solo_construct (size_t @var{maxmem}, char *@var{memout}, size_t *@var{alignment}
#+begin_deftypefun
Construct a new solo game in /memout/, writing at most /maxmem/ bytes.
Output the alignment requirement for /memout/ in /alignment/, and
return the required size.
#+end_deftypefun
#+attr_texinfo: :options {TarotSolo *} tarot_solo_alloc (void)
#+begin_deftypefun
#+texinfo: @deftypefunx {TarotSolo *} tarot_solo_alloc_fuzzy (double @var{fuzziness}, size_t @var{seed_size}, const void *@var{seed}, const TarotAi *@var{ai})
......
/* tarot implements the rules of the tarot game
* Copyright (C) 2019 Vivien Kraus
* Copyright (C) 2019, 2020 Vivien Kraus
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
......@@ -22,23 +22,12 @@
#include <stdalign.h>
#include "xalloc.h"
#ifdef __FRAMAC__
#undef alignof
#define alignof(x) (16)
#endif /* __FRAMAC__ */
static inline TarotSolo *
solo_alloc_aux (const TarotAi * ai)
{
size_t alignment;
size_t required = solo_construct (0, NULL, &alignment, ai);
size_t unused;
void *mem = xmalloc (required);
assert (alignment >= 1 && alignment <= alignof (max_align_t));
unused = solo_construct (required, mem, &alignment, ai);
assert (unused == required);
(void) unused;
return mem;
TarotSolo *ret = xmalloc (sizeof (TarotSolo));
solo_initialize (ret, ai);
return ret;
}
TarotSolo *
......@@ -93,15 +82,6 @@ tarot_solo_free (TarotSolo * solo)
free (solo);
}
size_t
tarot_solo_construct (size_t max_mem, char *mem, size_t *alignment)
{
TarotAi *perceptron = tarot_ai_alloc_perceptron ();
size_t ret = solo_construct (max_mem, mem, alignment, perceptron);
tarot_ai_free (perceptron);
return ret;
}
void
tarot_solo_copy (TarotSolo * dest, const TarotSolo * source)
{
......
/* tarot implements the rules of the tarot game
* Copyright (C) 2019 Vivien Kraus
* Copyright (C) 2019, 2020 Vivien Kraus
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
......@@ -47,15 +47,6 @@ extern "C"
TarotSolo *tarot_solo_dup (const TarotSolo * source);
void tarot_solo_free (TarotSolo * solo);
/**
* tarot_solo_construct:
* @max_mem: available number of bytes in @mem
* @mem_out: (array length=max_mem): available aligned memory
* @alignment: (out): the game alignment
*/
size_t tarot_solo_construct (size_t max_mem, char *mem_out,
size_t *alignment);
void tarot_solo_copy (TarotSolo * dest, const TarotSolo * source);
void tarot_solo_copy_as (TarotSolo * dest, const TarotSolo * source,
TarotPlayer who);
......
/* tarot implements the rules of the tarot game
* Copyright (C) 2019 Vivien Kraus
* Copyright (C) 2019, 2020 Vivien Kraus
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
......@@ -25,8 +25,7 @@
extern "C"
{
#endif /* __cplusplus */
static size_t solo_construct (size_t max_mem, char *mem_out,
size_t *alignment, const TarotAi * ai);
static void solo_initialize (TarotSolo * solo, const TarotAi * ai);
static void solo_destruct (TarotSolo * solo);
static void solo_copy (TarotSolo * dest, const TarotSolo * source);
static void solo_copy_as (TarotSolo * dest, const TarotSolo * source,
......
......@@ -30,21 +30,12 @@
static inline void solo_advance (TarotSolo * dest);
static inline size_t
solo_construct (size_t max_mem, char *mem, size_t *alignment,
const TarotAi * ai)
static inline void
solo_initialize (TarotSolo * solo, const TarotAi * ai)
{
size_t required = sizeof (TarotSolo);
*alignment = alignof (TarotSolo);
if (max_mem >= required)
{
TarotSolo *solo = (TarotSolo *) mem;
game_initialize (&(solo->game), 4, 0);
solo->myself = 0;
solo->ai = tarot_ai_dup (ai);
return max_mem;
}
return required;
game_initialize (&(solo->game), 4, 0);
solo->myself = 0;
solo->ai = tarot_ai_dup (ai);
}
static inline void
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment