Skip to content

Commit

Permalink
s/LuaUnitMaterial/LuaObjectMaterial/g
Browse files Browse the repository at this point in the history
s/LuaUnitRendering/LuaObjectRendering/g
generalize Lua*Material and the Lua*Rendering API
  • Loading branch information
rtri committed Nov 23, 2015
1 parent a23029f commit 95a1cac
Show file tree
Hide file tree
Showing 20 changed files with 432 additions and 393 deletions.
12 changes: 7 additions & 5 deletions rts/Game/SelectedUnitsAI.cpp
Expand Up @@ -398,9 +398,11 @@ void CSelectedUnitsHandlerAI::MakeFrontMove(Command* c,int player)

void CSelectedUnitsHandlerAI::CreateUnitOrder(std::multimap<float,int>& out,int player)
{
const vector<int>& netUnits = selectedUnitsHandler.netSelected[player];
for (vector<int>::const_iterator ui = netUnits.begin(); ui != netUnits.end(); ++ui) {
const std::vector<int>& netUnits = selectedUnitsHandler.netSelected[player];

for (auto ui = netUnits.cbegin(); ui != netUnits.cend(); ++ui) {
const CUnit* unit = unitHandler->units[*ui];

if (unit) {
const UnitDef* ud = unit->unitDef;
float range = unit->maxRange;
Expand Down Expand Up @@ -589,7 +591,7 @@ void CSelectedUnitsHandlerAI::SelectCircleUnits(
if (p == NULL)
return;

const vector<CUnit*>& tmpUnits = quadField->GetUnitsExact(pos, radius, false);
const std::vector<CUnit*>& tmpUnits = quadField->GetUnitsExact(pos, radius, false);

const float radiusSqr = radius * radius;
const unsigned int count = tmpUnits.size();
Expand Down Expand Up @@ -622,7 +624,7 @@ void CSelectedUnitsHandlerAI::SelectRectangleUnits(
const float3& pos0,
const float3& pos1,
int player,
vector<int>& units
std::vector<int>& units
) {
units.clear();

Expand All @@ -637,7 +639,7 @@ void CSelectedUnitsHandlerAI::SelectRectangleUnits(
const float3 mins(std::min(pos0.x, pos1.x), 0.0f, std::min(pos0.z, pos1.z));
const float3 maxs(std::max(pos0.x, pos1.x), 0.0f, std::max(pos0.z, pos1.z));

const vector<CUnit*>& tmpUnits = quadField->GetUnitsExact(mins, maxs);
const std::vector<CUnit*>& tmpUnits = quadField->GetUnitsExact(mins, maxs);

const unsigned int count = tmpUnits.size();
const int allyTeam = teamHandler->AllyTeam(p->team);
Expand Down
2 changes: 1 addition & 1 deletion rts/Lua/CMakeLists.txt
Expand Up @@ -22,6 +22,7 @@ SET(sources_engine_Lua
"${CMAKE_CURRENT_SOURCE_DIR}/LuaMaterial.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/LuaMathExtra.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/LuaMetalMap.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/LuaObjectRendering.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/LuaOpenGL.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/LuaOpenGLUtils.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/LuaParser.cpp"
Expand All @@ -39,7 +40,6 @@ SET(sources_engine_Lua
"${CMAKE_CURRENT_SOURCE_DIR}/LuaUI.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/LuaUICommand.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/LuaUnitDefs.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/LuaUnitRendering.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/LuaUnsyncedCtrl.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/LuaUnsyncedRead.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/LuaUtils.cpp"
Expand Down
78 changes: 37 additions & 41 deletions rts/Lua/LuaMaterial.cpp
Expand Up @@ -11,7 +11,7 @@
#include "Rendering/ShadowHandler.h"
#include "Rendering/Env/CubeMapHandler.h"
#include "Rendering/Env/ISky.h"
#include "Sim/Units/Unit.h"
#include "Sim/Objects/SolidObject.h"
#include "System/Log/ILog.h"
#include "System/Util.h"

Expand All @@ -36,23 +36,23 @@ LuaMatHandler& luaMatHandler = LuaMatHandler::handler;
// LuaUnitUniforms
//

void LuaUnitUniforms::Execute(const CUnit* unit) const
void LuaUnitUniforms::Execute(const CSolidObject* o) const
{
// FIXME use vertex attributes
if (!haveUniforms) {
if (!haveUniforms)
return;
}

if (speedLoc >= 0) {
glUniformf3(speedLoc, unit->speed);
glUniformf3(speedLoc, o->speed);
}
if (healthLoc >= 0) {
glUniform1f(healthLoc, unit->health / unit->maxHealth);
glUniform1f(healthLoc, o->health / o->maxHealth);
}
if (unitIDLoc >= 0) {
glUniform1i(unitIDLoc, unit->id);
glUniform1i(unitIDLoc, o->id);
}
if (teamIDLoc >= 0) {
glUniform1i(teamIDLoc, unit->id);
glUniform1i(teamIDLoc, o->team);
}
if (customLoc >= 0) {
if (customCount > 0) {
Expand Down Expand Up @@ -108,10 +108,10 @@ LuaUnitUniforms::LuaUnitUniforms(const LuaUnitUniforms& u)
/******************************************************************************/
/******************************************************************************/
//
// LuaUnitMaterial
// LuaObjectMaterial
//

bool LuaUnitMaterial::SetLODCount(unsigned int count)
bool LuaObjectMaterial::SetLODCount(unsigned int count)
{
lodCount = count;
lastLOD = lodCount - 1;
Expand All @@ -120,7 +120,7 @@ bool LuaUnitMaterial::SetLODCount(unsigned int count)
}


bool LuaUnitMaterial::SetLastLOD(unsigned int lod)
bool LuaObjectMaterial::SetLastLOD(unsigned int lod)
{
lastLOD = std::min(lod, lodCount - 1);
return true;
Expand Down Expand Up @@ -465,11 +465,18 @@ LuaMatRef::LuaMatRef(const LuaMatRef& mr)
}


void LuaMatRef::AddUnit(CUnit* unit)
void LuaMatRef::AddUnit(CSolidObject* o)
{
if (bin != NULL) {
bin->AddUnit(o);
}
}

void LuaMatRef::AddFeature(CSolidObject* o)
{
if (bin != NULL) {
bin->AddUnit(unit);
}
if (bin != NULL) {
bin->AddFeature(o);
}
}


Expand All @@ -496,7 +503,8 @@ void LuaMatBin::UnRef()

void LuaMatBin::Print(const string& indent) const
{
LOG("%sunitCount = %i", indent.c_str(), (int)units.size());
LOG("%s|units| = %lu", indent.c_str(), units.size());
LOG("%s|features| = %lu", indent.c_str(), features.size());
LOG("%spointer = %p", indent.c_str(), this);
LuaMaterial::Print(indent + " ");
}
Expand Down Expand Up @@ -551,24 +559,29 @@ LuaMatRef LuaMatHandler::GetRef(const LuaMaterial& mat)
}


void LuaMatHandler::ClearBins(LuaMatType type)
void LuaMatHandler::ClearBins(LuaObjType objType, LuaMatType matType)
{
if ((type < 0) || (type >= LUAMAT_TYPE_COUNT)) {
if ((matType < 0) || (matType >= LUAMAT_TYPE_COUNT))
return;
}
LuaMatBinSet& binSet = binTypes[type];

LuaMatBinSet& binSet = binTypes[matType];
LuaMatBinSet::iterator it;

for (it = binSet.begin(); it != binSet.end(); ++it) {
LuaMatBin* bin = *it;
bin->Clear();

switch (objType) {
case LUAOBJ_UNIT : { bin->ClearUnits (); } break;
case LUAOBJ_FEATURE: { bin->ClearFeatures(); } break;
}
}
}


void LuaMatHandler::ClearBins()
void LuaMatHandler::ClearBins(LuaObjType objType)
{
for (int m = 0; m < LUAMAT_TYPE_COUNT; m++) {
ClearBins(LuaMatType(m));
ClearBins(objType, LuaMatType(m));
}
}

Expand Down Expand Up @@ -618,22 +631,5 @@ void LuaMatHandler::PrintAllBins(const string& indent) const
/******************************************************************************/
/******************************************************************************/

float LuaUnitMaterialData::UNIT_GLOBAL_LOD_FACTOR = 1.0f;

unsigned int LuaUnitMaterialData::CalcCurrentLOD(float lodDist, unsigned int lastLOD) const
{
if (lastLOD == 0)
return 0;

// positive values only!
const float lpp = std::max(0.0f, lodDist * UNIT_GLOBAL_LOD_FACTOR);

for (/* no-op */; lastLOD != 0; lastLOD--) {
if (lpp > lodLengths[lastLOD]) {
break;
}
}

return lastLOD;
}
float LuaObjectMaterialData::GLOBAL_LOD_FACTORS[2] = {1.0f, 1.0f};

24 changes: 15 additions & 9 deletions rts/Lua/LuaMaterial.h
Expand Up @@ -6,17 +6,17 @@
#include <string>
#include <vector>
#include <set>

using std::string;
using std::vector;
using std::set;

#include "LuaOpenGLUtils.h"
#include "LuaUnitMaterial.h" // for LuaMatRef
#include "LuaObjectMaterial.h" // for LuaMatRef

#include "Rendering/GL/myGL.h"
#include "Rendering/ShadowHandler.h"

class CUnit;
class CSolidObject;


class LuaMatTexSetRef;
Expand Down Expand Up @@ -139,13 +139,17 @@ class LuaMatBin : public LuaMaterial {
friend class LuaMatHandler;

public:
void Clear() { units.clear(); }
const std::vector<CUnit*>& GetUnits() const { return units; }
void ClearUnits() { units.clear(); }
void ClearFeatures() { features.clear(); }

const std::vector<CSolidObject*>& GetUnits() const { return units; }
const std::vector<CSolidObject*>& GetFeatures() const { return features; }

void Ref();
void UnRef();

void AddUnit(CUnit* unit) { units.push_back(unit); }
void AddUnit(CSolidObject* o) { units.push_back(o); }
void AddFeature(CSolidObject* o) { features.push_back(o); }

void Print(const string& indent) const;

Expand All @@ -156,7 +160,9 @@ class LuaMatBin : public LuaMaterial {

private:
int refCount;
std::vector<CUnit*> units;

std::vector<CSolidObject*> units;
std::vector<CSolidObject*> features;
};


Expand All @@ -183,8 +189,8 @@ class LuaMatHandler {
return binTypes[type];
}

void ClearBins();
void ClearBins(LuaMatType type);
void ClearBins(LuaObjType objType);
void ClearBins(LuaObjType objType, LuaMatType type);

void FreeBin(LuaMatBin* bin);

Expand Down

1 comment on commit 95a1cac

@abma
Copy link
Contributor

@abma abma commented on 95a1cac Nov 23, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

introduces these compiler warnings:
rts/Lua/LuaObjectRendering.cpp:667:1: warning: control reaches end of non-void function [-Wreturn-type]
rts/Lua/LuaObjectMaterial.h:225:2: warning: control reaches end of non-void function [-Wreturn-type]

Please sign in to comment.