1 | /* |
1 | /* |
2 | * This file is part of Deliantra, the Roguelike Realtime MMORPG. |
2 | * This file is part of Deliantra, the Roguelike Realtime MMORPG. |
3 | * |
3 | * |
|
|
4 | * Copyright (©) 2017,2018 Marc Alexander Lehmann / the Deliantra team |
4 | * Copyright (©) 2005,2006,2007,2008,2009,2010,2011,2012 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
5 | * Copyright (©) 2005,2006,2007,2008,2009,2010,2011,2012,2013,2014,2015,2016 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
5 | * Copyright (©) 2001 Mark Wedel & Crossfire Development Team |
6 | * Copyright (©) 2001 Mark Wedel & Crossfire Development Team |
6 | * Copyright (©) 1992 Frank Tore Johansen |
7 | * Copyright (©) 1992 Frank Tore Johansen |
7 | * |
8 | * |
8 | * Deliantra is free software: you can redistribute it and/or modify it under |
9 | * Deliantra is free software: you can redistribute it and/or modify it under |
9 | * the terms of the Affero GNU General Public License as published by the |
10 | * the terms of the Affero GNU General Public License as published by the |
… | |
… | |
108 | } |
109 | } |
109 | |
110 | |
110 | return shstr (buf); |
111 | return shstr (buf); |
111 | } |
112 | } |
112 | |
113 | |
113 | noinline SV * |
114 | ecb_noinline SV * |
114 | random_map_params::opt_sv (const char *option) const |
115 | random_map_params::opt_sv (const char *option) const |
115 | { |
116 | { |
116 | SV **he = hv_fetch (hv, option, strlen (option), 0); |
117 | SV **he = hv_fetch (hv, option, strlen (option), 0); |
117 | |
118 | |
118 | return he ? *he : 0; |
119 | return he ? *he : 0; |
119 | } |
120 | } |
120 | |
121 | |
121 | noinline const_utf8_string |
122 | ecb_noinline const_utf8_string |
122 | random_map_params::get_str (const char *option, const_utf8_string fallback) const |
123 | random_map_params::get_str (const char *option, const_utf8_string fallback) const |
123 | { |
124 | { |
124 | SV *sv = opt_sv (option); |
125 | SV *sv = opt_sv (option); |
125 | return sv ? cfSvPVutf8_nolen (sv) : fallback; |
126 | return sv ? cfSvPVutf8_nolen (sv) : fallback; |
126 | } |
127 | } |
127 | |
128 | |
128 | noinline IV |
129 | ecb_noinline IV |
129 | random_map_params::get_iv (const char *option, IV fallback) const |
130 | random_map_params::get_iv (const char *option, IV fallback) const |
130 | { |
131 | { |
131 | SV *sv = opt_sv (option); |
132 | SV *sv = opt_sv (option); |
132 | return sv ? SvIV (sv) : fallback; |
133 | return sv ? SvIV (sv) : fallback; |
133 | } |
134 | } |
134 | |
135 | |
135 | noinline UV |
136 | ecb_noinline UV |
136 | random_map_params::get_uv (const char *option, UV fallback) const |
137 | random_map_params::get_uv (const char *option, UV fallback) const |
137 | { |
138 | { |
138 | SV *sv = opt_sv (option); |
139 | SV *sv = opt_sv (option); |
139 | return sv ? SvUV (sv) : fallback; |
140 | return sv ? SvUV (sv) : fallback; |
140 | } |
141 | } |
141 | |
142 | |
142 | noinline NV |
143 | ecb_noinline NV |
143 | random_map_params::get_nv (const char *option, NV fallback) const |
144 | random_map_params::get_nv (const char *option, NV fallback) const |
144 | { |
145 | { |
145 | SV *sv = opt_sv (option); |
146 | SV *sv = opt_sv (option); |
146 | return sv ? SvNV (sv) : fallback; |
147 | return sv ? SvNV (sv) : fallback; |
147 | } |
148 | } |
148 | |
149 | |
149 | noinline void |
150 | ecb_noinline void |
150 | random_map_params::set (const char *option, SV *value) const |
151 | random_map_params::set (const char *option, SV *value) const |
151 | { |
152 | { |
152 | int len = strlen (option); |
153 | int len = strlen (option); |
153 | |
154 | |
154 | if (value) |
155 | if (value) |
155 | hv_store (hv, option, len, value, 0); |
156 | hv_store (hv, option, len, value, 0); |
156 | else |
157 | else |
157 | hv_delete (hv, option, len, G_DISCARD); |
158 | hv_delete (hv, option, len, G_DISCARD); |
158 | } |
159 | } |
159 | |
160 | |
160 | noinline void |
161 | ecb_noinline void |
161 | random_map_params::set (const char *option, const_utf8_string value) const |
162 | random_map_params::set (const char *option, const_utf8_string value) const |
162 | { |
163 | { |
163 | set (option, value && *value ? newSVpvn_utf8 (value, strlen (value), 1) : 0); |
164 | set (option, value && *value ? newSVpvn_utf8 (value, strlen (value), 1) : 0); |
164 | } |
165 | } |
165 | |
166 | |