Changeset View
Changeset View
Standalone View
Standalone View
ps/trunk/source/graphics/ObjectBase.cpp
/* Copyright (C) 2018 Wildfire Games. | /* Copyright (C) 2019 Wildfire Games. | ||||
* 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 All 14 Lines | |||||
#include "ObjectManager.h" | #include "ObjectManager.h" | ||||
#include "ps/XML/Xeromyces.h" | #include "ps/XML/Xeromyces.h" | ||||
#include "ps/Filesystem.h" | #include "ps/Filesystem.h" | ||||
#include "ps/CLogger.h" | #include "ps/CLogger.h" | ||||
#include "lib/timer.h" | #include "lib/timer.h" | ||||
#include "maths/MathUtil.h" | #include "maths/MathUtil.h" | ||||
#include <boost/random/uniform_int.hpp> | #include <boost/random/uniform_int_distribution.hpp> | ||||
CObjectBase::CObjectBase(CObjectManager& objectManager) | CObjectBase::CObjectBase(CObjectManager& objectManager) | ||||
: m_ObjectManager(objectManager) | : m_ObjectManager(objectManager) | ||||
{ | { | ||||
m_Properties.m_CastShadows = false; | m_Properties.m_CastShadows = false; | ||||
m_Properties.m_FloatOnWater = false; | m_Properties.m_FloatOnWater = false; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 508 Lines • ▼ Show 20 Lines | else | ||||
totalFreq += (*grp)[i].m_Frequency; | totalFreq += (*grp)[i].m_Frequency; | ||||
// Someone might be silly and set all variants to have freq==0, in | // Someone might be silly and set all variants to have freq==0, in | ||||
// which case we just pretend they're all 1 | // which case we just pretend they're all 1 | ||||
bool allZero = (totalFreq == 0); | bool allZero = (totalFreq == 0); | ||||
if (allZero) totalFreq = (int)grp->size(); | if (allZero) totalFreq = (int)grp->size(); | ||||
// Choose a random number in the interval [0..totalFreq) | // Choose a random number in the interval [0..totalFreq) | ||||
int randNum = boost::uniform_int<>(0, totalFreq-1)(rng); | int randNum = boost::random::uniform_int_distribution<int>(0, totalFreq-1)(rng); | ||||
// and use that to choose one of the variants | // and use that to choose one of the variants | ||||
for (size_t i = 0; i < grp->size(); ++i) | for (size_t i = 0; i < grp->size(); ++i) | ||||
{ | { | ||||
randNum -= (allZero ? 1 : (*grp)[i].m_Frequency); | randNum -= (allZero ? 1 : (*grp)[i].m_Frequency); | ||||
if (randNum < 0) | if (randNum < 0) | ||||
{ | { | ||||
remainingSelections.insert((*grp)[i].m_VariantName); | remainingSelections.insert((*grp)[i].m_VariantName); | ||||
▲ Show 20 Lines • Show All 120 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator