Changeset View
Standalone View
source/simulation2/components/CCmpRangeManager.cpp
/* Copyright (C) 2018 Wildfire Games. | /* Copyright (C) 2019 Wildfire Games. | ||||
Silier: 2019 | |||||
* This file is part of 0 A.D. | * This file is part of 0 A.D. | ||||
* | * | ||||
* 0 A.D. is free software: you can redistribute it and/or modify | * 0 A.D. is free software: you can redistribute it and/or modify | ||||
* it under the terms of the GNU General Public License as published by | * it under the terms of the GNU General Public License as published by | ||||
* the Free Software Foundation, either version 2 of the License, or | * the Free Software Foundation, either version 2 of the License, or | ||||
* (at your option) any later version. | * (at your option) any later version. | ||||
* | * | ||||
* 0 A.D. is distributed in the hope that it will be useful, | * 0 A.D. is distributed in the hope that it will be useful, | ||||
▲ Show 20 Lines • Show All 2,421 Lines • ▼ Show 20 Lines | for (i32 j = 0; j < m_TerrainVerticesPerSide; j++) | ||||
{ | { | ||||
exploredVertices += 1; | exploredVertices += 1; | ||||
break; | break; | ||||
} | } | ||||
} | } | ||||
return exploredVertices * 100 / m_TotalInworldVertices; | return exploredVertices * 100 / m_TotalInworldVertices; | ||||
} | } | ||||
virtual bool CanPlayerExplorePosition(entity_pos_t x, entity_pos_t y, player_id_t player) const | |||||
{ | |||||
int i = (x / static_cast<int>(TERRAIN_TILE_SIZE)).ToInt_RoundToNearest(); | |||||
Done Inline Actionsstatic_cast<int> Though I'm not sure the cast is needed at all. Stan: static_cast<int> Though I'm not sure the cast is needed at all. | |||||
Done Inline ActionsI've got no clue as to what that means ;) Freagarach: I've got no clue as to what that means ;) | |||||
Done Inline ActionsIn JavaScript you don't have to bother much which types as even if you do sometehing stupid most of the time it will fix it for you. In C++ one has to be careful as to not make divisions on int because 1 /2 = 0 (type)(number) is a C- style cast which mean it will try static_cast<type>(number), then reinterpret_cast<type>(number), then const_cast<type>(number) to make the conversion. In this case though .ToInt_RoundToNearest(); will probably cast the result to int anyway. @Angen might tell you more about it :) Stan: In JavaScript you don't have to bother much which types as even if you do sometehing stupid… | |||||
Done Inline Actionsfirst one is enity_post type so result of / is basicly float with fixed floating point so result represents float number but with type entity_pos_t This formula is used to convert position to tiles when determining if player sees entity. (so nothing made up) Terrain_tile_size is integer number but macro does not know types. Silier: first one is enity_post type so result of / is basicly float with fixed floating point so… | |||||
Done Inline ActionsI meant int a = 1 int b = 2 int c = a / b // 0 not the round to nearest :) Stan: I meant int a = 1 int b = 2 int c = a / b // 0
not the round to nearest :) | |||||
Done Inline ActionsI know :) I was reacting to
and to be correct 0.5 -> 1 Back to the point Silier: I know :) I was reacting to
> ToInt_RoundToNearest(); will probably cast the result to int… | |||||
Done Inline ActionsSo it is correct as is? Freagarach: So it is correct as is? | |||||
Done Inline Actionsstatic_cast<int>(TERRAIN_TILE_SIZE) Silier: static_cast<int>(TERRAIN_TILE_SIZE) | |||||
int j = (y / static_cast<int>(TERRAIN_TILE_SIZE)).ToInt_RoundToNearest(); | |||||
CLosQuerier los(GetSharedLosMask(player), m_LosState, m_TerrainVerticesPerSide); | |||||
return !los.IsExplored(i, j) && !LosIsOffWorld(i, j); | |||||
} | |||||
}; | }; | ||||
REGISTER_COMPONENT_TYPE(RangeManager) | REGISTER_COMPONENT_TYPE(RangeManager) |
2019