Changeset 406 for trunk/src/lua/lua_map_tile.cc
- Timestamp:
- 06/20/15 00:05:17 (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/lua/lua_map_tile.cc
r395 r406 40 40 static map_tile* nlua_to_pmap_tile( lua_State* L, int index ) 41 41 { 42 return (map_tile*)luaL_checkudata( L, index, NLUA_MAP_TILE_METATABLE);42 return reinterpret_cast<map_tile*>( luaL_checkudata( L, index, NLUA_MAP_TILE_METATABLE ) ); 43 43 } 44 44 45 45 static void nlua_push_map_tile( lua_State* L, const map_tile& tile ) 46 46 { 47 map_tile* result = (map_tile*)lua_newuserdata( L, sizeof(map_tile) );47 map_tile* result = reinterpret_cast<map_tile*>( lua_newuserdata( L, sizeof(map_tile) ) ); 48 48 *result = tile; 49 49 luaL_setmetatable( L, NLUA_MAP_TILE_METATABLE ); … … 65 65 map_tile tile; 66 66 67 tile.size_y = (nv::uint16)( nv::count( code.begin(), code.end(), '\n' ) + 1 );68 tile.size_x = (nv::uint16)( code.find( '\n' ) );67 tile.size_y = nv::uint16( nv::count( code.begin(), code.end(), '\n' ) + 1 ); 68 tile.size_x = nv::uint16( code.find( '\n' ) ); 69 69 if ( tile.size_x == 0 ) 70 70 { 71 tile.size_x = (nv::uint16)code.length();71 tile.size_x = nv::uint16( code.length() ); 72 72 } 73 73 tile.data = new nv::uint8[ tile.size_x * tile.size_y ]; … … 85 85 if ( lua_isstring( L, -2 ) && lua_objlen( L, -2 ) == 1 ) 86 86 { 87 translation[ (nv::uint8)( lua_tostring( L, -2 )[0] ) ] = nv::uint8( map_area->string_to_id( lua_tostring( L, -1 ) ) );87 translation[ nv::uint8( lua_tostring( L, -2 )[0] ) ] = nv::uint8( map_area->string_to_id( lua_tostring( L, -1 ) ) ); 88 88 } 89 89 // removes 'value'; keeps 'key' for next iteration */ … … 95 95 for ( nv::uint16 row = 0; row < tile.size_y; row++ ) 96 96 { 97 nv::uchar8 gylph = (nv::uchar8)code[ row * ( tile.size_x + 1 ) + line ];97 nv::uchar8 gylph = nv::uchar8( code[ row * ( tile.size_x + 1 ) + line ] ); 98 98 // TODO: check for errors 99 99 tile.data[ row * tile.size_x + line ] = translation[ gylph ]; … … 108 108 { 109 109 map_tile* old_tile = nlua_to_pmap_tile( L, 1 ); 110 map_tile* new_tile = (map_tile*) lua_newuserdata( L, sizeof( map_tile) );110 map_tile* new_tile = reinterpret_cast<map_tile*>( lua_newuserdata( L, sizeof( map_tile ) ) ); 111 111 new_tile->size_x = old_tile->size_x; 112 112 new_tile->size_y = old_tile->size_y; … … 246 246 nv::uint16 org_x = tile->size_x; 247 247 nv::uint16 org_y = tile->size_y; 248 nv::uint16 new_x = ( nv::uint16 )nv::accumulate( sizes_x.begin(), sizes_x.end(), 0);249 nv::uint16 new_y = ( nv::uint16 )nv::accumulate( sizes_y.begin(), sizes_y.end(), 0);248 nv::uint16 new_x = nv::uint16( nv::accumulate( sizes_x.begin(), sizes_x.end(), 0 ) ); 249 nv::uint16 new_y = nv::uint16( nv::accumulate( sizes_y.begin(), sizes_y.end(), 0 ) ); 250 250 251 251 nv::uint8* data = new nv::uint8[ new_x * new_y ]; … … 274 274 static int nlua_map_tile_raw_get( lua_State* L ) 275 275 { 276 map_tile* tile = (map_tile*)lua_touserdata( L, 1);276 map_tile* tile = reinterpret_cast<map_tile*>( lua_touserdata( L, 1 ) ); 277 277 if ( lua_type( L, 2 ) == LUA_TNUMBER ) 278 278 { … … 289 289 static int nlua_map_tile_raw_set( lua_State* L ) 290 290 { 291 map_tile* tile = (map_tile*)lua_touserdata( L, 1);291 map_tile* tile = reinterpret_cast<map_tile*>( lua_touserdata( L, 1 ) ); 292 292 if ( lua_type( L, 2 ) == LUA_TNUMBER ) 293 293 { 294 tile->data[ ( lua_tointeger( L, 2 ) - 1 ) + ( lua_tointeger( L, 3 ) - 1 ) * tile->size_x ] = (nv::uint8)lua_tointeger( L, 3);294 tile->data[ ( lua_tointeger( L, 2 ) - 1 ) + ( lua_tointeger( L, 3 ) - 1 ) * tile->size_x ] = nv::uint8( lua_tointeger( L, 3 ) ); 295 295 } 296 296 else 297 297 { 298 298 nv::ivec2 coord = nv::lua::detail::to_coord( L, 2 ); 299 tile->data[ ( coord.x - 1 ) + ( coord.y - 1 ) * tile->size_x ] = (nv::uint8)lua_tointeger( L, 3);299 tile->data[ ( coord.x - 1 ) + ( coord.y - 1 ) * tile->size_x ] = nv::uint8( lua_tointeger( L, 3 ) ); 300 300 } 301 301 return 0; … … 304 304 static int nlua_map_tile_ascii_get( lua_State* L ) 305 305 { 306 map_tile* tile = (map_tile*)lua_touserdata( L, 1);306 map_tile* tile = reinterpret_cast<map_tile*>( lua_touserdata( L, 1 ) ); 307 307 if ( lua_type( L, 2 ) == LUA_TNUMBER ) 308 308 { … … 319 319 static int nlua_map_tile_ascii_set( lua_State* L ) 320 320 { 321 map_tile* tile = (map_tile*)lua_touserdata( L, 1);321 map_tile* tile = reinterpret_cast<map_tile*>( lua_touserdata( L, 1 ) ); 322 322 if ( lua_type( L, 2 ) == LUA_TNUMBER ) 323 323 { 324 tile->ascii[ ( lua_tointeger( L, 2 ) - 1 ) + ( lua_tointeger( L, 3 ) - 1 ) * tile->size_x ] = (nv::uint8)lua_tointeger( L, 3);324 tile->ascii[ ( lua_tointeger( L, 2 ) - 1 ) + ( lua_tointeger( L, 3 ) - 1 ) * tile->size_x ] = nv::uint8( lua_tointeger( L, 3 ) ); 325 325 } 326 326 else 327 327 { 328 328 nv::ivec2 coord = nv::lua::detail::to_coord( L, 2 ); 329 tile->ascii[ ( coord.x - 1 ) + ( coord.y - 1 ) * tile->size_x ] = (nv::uint8)lua_tointeger( L, 3);329 tile->ascii[ ( coord.x - 1 ) + ( coord.y - 1 ) * tile->size_x ] = nv::uint8( lua_tointeger( L, 3 ) ); 330 330 } 331 331 return 0; … … 334 334 static int nlua_map_tile_gc( lua_State* L ) 335 335 { 336 map_tile* tile = (map_tile*)lua_touserdata( L, 1);336 map_tile* tile = reinterpret_cast<map_tile*>( lua_touserdata( L, 1 ) ); 337 337 if ( tile != nullptr ) 338 338 {
Note: See TracChangeset
for help on using the changeset viewer.