From b2be39b5761c0b389cced344985f230cd1313708 Mon Sep 17 00:00:00 2001 From: Armin Burgmeier Date: Mon, 7 Jan 2013 21:07:58 +0100 Subject: [PATCH] Handle-ify the random seed setting --- CMakeLists.txt | 4 +- .../random-handle.cpp} | 14 ++---- src/mape/cpp-handles/random-handle.h | 29 +++++++++++ src/mape/random.c | 49 +++++++++++++++++++ src/mape/random.h | 14 ++---- 5 files changed, 91 insertions(+), 19 deletions(-) rename src/mape/{random.cpp => cpp-handles/random-handle.cpp} (77%) create mode 100644 src/mape/cpp-handles/random-handle.h create mode 100644 src/mape/random.c diff --git a/CMakeLists.txt b/CMakeLists.txt index 0a2c0db7c..46c1374f3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -565,6 +565,8 @@ set(MAPE_SOURCES src/mape/cpp-handles/mapgen-handle.cpp src/mape/cpp-handles/material-handle.h src/mape/cpp-handles/material-handle.cpp + src/mape/cpp-handles/random-handle.h + src/mape/cpp-handles/random-handle.cpp src/mape/cpp-handles/texture-handle.h src/mape/cpp-handles/texture-handle.cpp src/mape/configfile.c @@ -595,7 +597,7 @@ set(MAPE_SOURCES src/mape/preferencesdialog.h src/mape/preview.c src/mape/preview.h - src/mape/random.cpp + src/mape/random.c src/mape/random.h src/mape/statusbar.c src/mape/statusbar.h diff --git a/src/mape/random.cpp b/src/mape/cpp-handles/random-handle.cpp similarity index 77% rename from src/mape/random.cpp rename to src/mape/cpp-handles/random-handle.cpp index 28b42e584..9670c2663 100644 --- a/src/mape/random.cpp +++ b/src/mape/cpp-handles/random-handle.cpp @@ -15,19 +15,15 @@ * See clonk_trademark_license.txt for full license. */ -#define MAPE_COMPILING_CPP - -#include -#include -#include - -#include "mape/random.h" +#include "C4Include.h" +#include "C4Random.h" +#include "mape/cpp-handles/random-handle.h" extern "C" { -void mape_random_seed(unsigned int seed) +void c4_random_handle_seed(unsigned int seed) { - FixedRandom(seed); + FixedRandom(seed); } } // extern "C" diff --git a/src/mape/cpp-handles/random-handle.h b/src/mape/cpp-handles/random-handle.h new file mode 100644 index 000000000..0bc679ab4 --- /dev/null +++ b/src/mape/cpp-handles/random-handle.h @@ -0,0 +1,29 @@ +/* + * mape - C4 Landscape.txt editor + * + * Copyright (c) 2005-2009 Armin Burgmeier + * + * Portions might be copyrighted by other authors who have contributed + * to OpenClonk. + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * See isc_license.txt for full license and disclaimer. + * + * "Clonk" is a registered trademark of Matthes Bender. + * See clonk_trademark_license.txt for full license. + */ + +#ifndef INC_MAPE_C4_RANDOM_HANDLE_H +#define INC_MAPE_C4_RANDOM_HANDLE_H + +#include + +G_BEGIN_DECLS + +void c4_random_handle_seed(unsigned int seed); + +G_END_DECLS + +#endif /* INC_MAPE_C4_RANDOM_HANDLE_H */ diff --git a/src/mape/random.c b/src/mape/random.c new file mode 100644 index 000000000..bd2c13980 --- /dev/null +++ b/src/mape/random.c @@ -0,0 +1,49 @@ +/* + * mape - C4 Landscape.txt editor + * + * Copyright (c) 2005-2009 Armin Burgmeier + * + * Portions might be copyrighted by other authors who have contributed + * to OpenClonk. + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * See isc_license.txt for full license and disclaimer. + * + * "Clonk" is a registered trademark of Matthes Bender. + * See clonk_trademark_license.txt for full license. + */ + +/** + * SECTION:mape-random + * @title: MapeRandom + * @short_description: Interface to the random number generator + * @include: mape/random.h + * @stability: Unstable + * + * These functions provide a simple interface to the random number generator + * used for map generation in the Clonk engine. + **/ + +#include "mape/cpp-handles/random-handle.h" +#include "mape/random.h" + +/* + * Public API. + */ + +/** + * mape_random_seed: + * @seed: Value to seed the random number generator with. + * + * Sets the random seed for the Clonk random number generator that is used + * when generating a map with C4MapCreatorS2. + */ +void +mape_random_seed(unsigned int seed) +{ + c4_random_handle_seed(seed); +} + +/* vim:set et sw=2 ts=2: */ diff --git a/src/mape/random.h b/src/mape/random.h index 945fe588f..a70cf993b 100644 --- a/src/mape/random.h +++ b/src/mape/random.h @@ -18,18 +18,14 @@ #ifndef INC_MAPE_RANDOM_H #define INC_MAPE_RANDOM_H -#include "mape/forward.h" +#include -/* Simple C-based interface to C4Random */ - -#ifdef MAPE_COMPILING_CPP -extern "C" { -#endif +G_BEGIN_DECLS void mape_random_seed(unsigned int seed); -#ifdef MAPE_COMPILING_CPP -} /* extern "C" */ -#endif +G_END_DECLS #endif /* INC_MAPE_RANDOM_H */ + +/* vim:set et sw=2 ts=2: */