| 1 |
# Miscellaneous routines for games |
| 2 |
# Copyright (C) 2008 Masami Hiramatsu <[email protected]> |
| 3 |
# |
| 4 |
# This file is free software and is distributed under the terms of the GNU |
| 5 |
# General Public License (GPL); either version 2, or (at your option) any |
| 6 |
# later version. |
| 7 |
|
| 8 |
global __GM_rand_seed |
| 9 |
|
| 10 |
function game_srand(seed:long) |
| 11 |
{ |
| 12 |
__GM_rand_seed = seed |
| 13 |
} |
| 14 |
|
| 15 |
function __game_lfsr(val:long) /* pure */ |
| 16 |
%{ |
| 17 |
u64 r = THIS->val; |
| 18 |
r = (r >> 1) ^ ((-(r & 1ULL)) & 0xd800000000000000ULL); |
| 19 |
THIS->__retvalue = r; |
| 20 |
%} |
| 21 |
|
| 22 |
function game_rand() |
| 23 |
{ |
| 24 |
return __GM_rand_seed = __game_lfsr(__GM_rand_seed) |
| 25 |
} |
| 26 |
|
| 27 |
function game_urand() |
| 28 |
{ |
| 29 |
rand = game_rand() |
| 30 |
return rand<0?-rand:rand |
| 31 |
} |