Skip to content

Commit

Permalink
Use renderer specific color conversion for BuildingInstaller
Browse files Browse the repository at this point in the history
  • Loading branch information
IonAgorria committed Feb 12, 2024
1 parent 6bc292c commit 1e11d31
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 53 deletions.
6 changes: 4 additions & 2 deletions Source/Render/inc/IRenderDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,10 @@ class cInterfaceRenderDevice : public cUnknownClass
cInterfaceRenderDevice();
~cInterfaceRenderDevice() override;

// Runtime set methods

ColorConversionFunc ConvertColor = nullptr;

// Common methods

virtual uint32_t GetWindowCreationFlags() const { return 0; }
Expand Down Expand Up @@ -261,8 +265,6 @@ class cInterfaceRenderDevice : public cUnknownClass

// Decl only methods

ColorConversionFunc ConvertColor = nullptr;

virtual eRenderDeviceSelection GetRenderSelection() const = 0;

virtual bool ChangeSize(int xScr,int yScr,int mode) = 0;
Expand Down
47 changes: 15 additions & 32 deletions Source/UserInterface/Installer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,7 @@

terBuildingInstaller::terBuildingInstaller(bool a_light_show)
{
Attribute = 0;
ObjectPoint = 0;
BaseBuff = 0;
BaseBuffSX = BaseBuffSY = 0;
pTexture = 0;
plane = 0;

light_show = a_light_show;
connection_icon_ = new terIconBuilding(terModelBuildingNoConnection);
Expand All @@ -42,15 +37,11 @@ void terBuildingInstaller::Clear()
{
CancelObject();

if(BaseBuff)
delete[] BaseBuff;
BaseBuff = 0;
delete[] BaseBuff;
BaseBuff = nullptr;
BaseBuffSX = BaseBuffSY = 0;

if(plane)
plane->Release();
plane=0;

RELEASE(plane);
RELEASE(pTexture);
}

Expand Down Expand Up @@ -78,11 +69,6 @@ void terBuildingInstaller::InitObject(const AttributeBase* attr)
OffsetX = OffsetY = 0;
visible_ = 0;
ObjectPoint->SetChannel(attr->UpgradeChainName,0);

if(attr->MilitaryUnit && attr->isBuilding() && attr->ShowCircles){
FireRadius = attr->fireRadius();
UmbrellaRadius = attr->fireRadiusMin();
}
}

void terBuildingInstaller::ConstructObject(terPlayer* player)
Expand Down Expand Up @@ -113,11 +99,11 @@ class terScanGroundLineBuffOp
{
int cnt, max;
int x0_, y0_, sx_, sy_;
char* buffer_;
uint8_t* buffer_;
bool building_;

public:
terScanGroundLineBuffOp(int x0,int y0,int sx,int sy, char* buffer)
terScanGroundLineBuffOp(int x0,int y0,int sx,int sy, uint8_t* buffer)
{
x0_ = x0;
y0_ = y0;
Expand All @@ -133,7 +119,7 @@ class terScanGroundLineBuffOp

max += x2 - x1 + 1;
unsigned short* buf = vMap.GABuf + vMap.offsetGBufWorldC(0, y);
char* pd = buffer_ + (y - y0_)*sx_ + x1 - x0_;
uint8_t* pd = buffer_ + (y - y0_)*sx_ + x1 - x0_;
while(x1 <= x2){
unsigned short p = *(buf + vMap.XCYCLG(x1 >> kmGrid));
if((p & GRIDAT_LEVELED) && !(p & (GRIDAT_MASK_CLUSTERID | GRIDAT_BUILDING | GRIDAT_BASE_OF_BUILDING_CORRUPT))){
Expand Down Expand Up @@ -194,11 +180,10 @@ void terBuildingInstaller::SetBuildPosition(const Vect3f& position,float angle,
y1 = y1 + 1;

if(!BaseBuff || BaseBuffSX < (x1 - x0) || BaseBuffSY < (y1 - y0)){
if(BaseBuff)
delete[] BaseBuff;
delete[] BaseBuff;
BaseBuffSX = x1 - x0;
BaseBuffSY = y1 - y0;
BaseBuff = new char[BaseBuffSX * BaseBuffSY];
BaseBuff = new uint8_t[BaseBuffSX * BaseBuffSY];
InitTexture();
}
memset(BaseBuff,0,BaseBuffSX * BaseBuffSY);
Expand Down Expand Up @@ -349,19 +334,17 @@ void terBuildingInstaller::UpdateInfo(cCamera *DrawNode)
sColor4c cempty(0,0,0,0);
sColor4c cgood = valid() ? sColor4c(0,255,0,128) : sColor4c(200,128,128,128);
sColor4c cbad(255,0,0,128);
char* p = BaseBuff;
uint8_t* p = BaseBuff;
for(int i = 0;i < BaseBuffSY;i++)
{
uint32_t * c = (uint32_t*)(buf + i * Pitch);
uint32_t* c = reinterpret_cast<uint32_t*>(buf + i * Pitch);
for(int j = 0;j < BaseBuffSX;j++)
{
if((*p) & 1){
if((*p) & 2)
*c = cgood.ARGB();
else
*c = cbad.ARGB();
}else
*c = cempty.ARGB();
if ((*p) & 1) {
*c = terRenderDevice->ConvertColor((*p) & 2 ? cgood : cbad);
} else {
*c = terRenderDevice->ConvertColor(cempty);
}
p++;
c++;
}
Expand Down
38 changes: 19 additions & 19 deletions Source/UserInterface/Installer.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,35 +33,35 @@ class terBuildingInstaller
bool buildingInArea() const { return buildingInArea_; }

private:
const AttributeBase* Attribute;
const AttributeBase* Attribute = nullptr;
Vect3f Position;
float Angle;
float FireRadius,UmbrellaRadius;
float Scale;
bool visible_;
bool valid_;
bool buildingInArea_;
cObjectNodeRoot* ObjectPoint;
float Angle = 0.0f;
float Scale = 0.0f;
bool visible_ = false;
bool valid_ = false;
bool buildingInArea_ = false;
cObjectNodeRoot* ObjectPoint = nullptr;

Vect2f pos_set;
float angle_set;

char* BaseBuff;
int BaseBuffSX,BaseBuffSY;
int OffsetX,OffsetY;
float angle_set = 0.0f;

uint8_t* BaseBuff = nullptr;
int BaseBuffSX = 0;
int BaseBuffSY = 0;
int OffsetX = 0;
int OffsetY = 0;

bool light_show;
class cTexture* pTexture;
class cPlane* plane;
bool light_show = false;
class cTexture* pTexture = nullptr;
class cPlane* plane = nullptr;

class terIconBuilding* connection_icon_;
class terIconBuilding* connection_icon_ = nullptr;

Vect3f old_build_position;
float old_build_angle;
float old_build_angle = 0.0f;
terPlayer* old_build_player;

void InitTexture();
void checkBuildingConnection();

bool checkScriptInstructions();
};
Expand Down

0 comments on commit 1e11d31

Please sign in to comment.