@@ -75,10 +75,7 @@ def __init__(
7575 seed = hash (seed )
7676
7777 self .random_c = ffi .gc (
78- ffi .cast (
79- "mersenne_data_t*" ,
80- lib .TCOD_random_new_from_seed (algorithm , seed & 0xFFFFFFFF ),
81- ),
78+ lib .TCOD_random_new_from_seed (algorithm , seed & 0xFFFFFFFF ),
8279 lib .TCOD_random_delete ,
8380 )
8481
@@ -141,22 +138,24 @@ def __getstate__(self) -> Any:
141138 """Pack the self.random_c attribute into a portable state."""
142139 state = self .__dict__ .copy ()
143140 state ["random_c" ] = {
144- "algo" : self .random_c .algo ,
145- "distribution" : self .random_c .distribution ,
146- "mt" : list (self .random_c .mt ),
147- "cur_mt" : self .random_c .cur_mt ,
148- "Q" : list (self .random_c .Q ),
149- "c" : self .random_c .c ,
150- "cur" : self .random_c .cur ,
141+ "mt_cmwc" : {
142+ "algorithm" : self .random_c .mt_cmwc .algorithm ,
143+ "distribution" : self .random_c .mt_cmwc .distribution ,
144+ "mt" : list (self .random_c .mt_cmwc .mt ),
145+ "cur_mt" : self .random_c .mt_cmwc .cur_mt ,
146+ "Q" : list (self .random_c .mt_cmwc .Q ),
147+ "c" : self .random_c .mt_cmwc .c ,
148+ "cur" : self .random_c .mt_cmwc .cur ,
149+ }
151150 }
152151 return state
153152
154153 def __setstate__ (self , state : Any ) -> None :
155154 """Create a new cdata object with the stored paramaters."""
156- try :
157- cdata = state [ "random_c" ]
158- except KeyError : # old/deprecated format
159- cdata = state ["cdata " ]
160- del state ["cdata" ]
161- state ["random_c" ] = ffi .new ("mersenne_data_t *" , cdata )
155+ if "algo" in state [ "random_c" ] :
156+ # Handle old/deprecated format. Covert to libtcod's new union type.
157+ state [ "random_c" ][ "algorithm" ] = state [ "random_c" ][ "algo" ]
158+ del state ["random_c" ][ "algo " ]
159+ state [ "random_c" ] = { "mt_cmwc" : state ["random_c" ]}
160+ state ["random_c" ] = ffi .new ("TCOD_Random *" , state [ "random_c" ] )
162161 self .__dict__ .update (state )
0 commit comments