mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-07-18 03:09:18 +02:00
static linking, largeaddressaware, basic tga texture downsampling
This commit is contained in:
9
EU07.cpp
9
EU07.cpp
@@ -32,8 +32,17 @@ Stele, firleju, szociu, hunter, ZiomalCl, OLI_EU and others
|
||||
#include "resource.h"
|
||||
#include "uilayer.h"
|
||||
|
||||
#ifdef EU07_BUILD_STATIC
|
||||
#pragma comment( lib, "glfw3.lib" )
|
||||
#pragma comment( lib, "glew32s.lib" )
|
||||
#else
|
||||
#ifdef _WINDOWS
|
||||
#pragma comment( lib, "glfw3dll.lib" )
|
||||
#else
|
||||
#pragma comment( lib, "glfw3.lib" )
|
||||
#endif
|
||||
#pragma comment( lib, "glew32.lib" )
|
||||
#endif // build_static
|
||||
#pragma comment( lib, "opengl32.lib" )
|
||||
#pragma comment( lib, "glu32.lib" )
|
||||
#pragma comment( lib, "dsound.lib" )
|
||||
|
||||
@@ -428,45 +428,47 @@ double TMoverParameters::Distance(const vector3 &s1, const vector3 &s2, const ve
|
||||
*/
|
||||
double TMoverParameters::CouplerDist(int Coupler)
|
||||
{ // obliczenie odległości pomiędzy sprzęgami (kula!)
|
||||
return Couplers[Coupler].CoupleDist =
|
||||
Distance(Loc, Couplers[Coupler].Connected->Loc, Dim,
|
||||
Couplers[Coupler].Connected->Dim); // odległość pomiędzy sprzęgami (kula!)
|
||||
Couplers[Coupler].CoupleDist =
|
||||
Distance(
|
||||
Loc, Couplers[Coupler].Connected->Loc,
|
||||
Dim, Couplers[Coupler].Connected->Dim); // odległość pomiędzy sprzęgami (kula!)
|
||||
|
||||
return Couplers[ Coupler ].CoupleDist;
|
||||
};
|
||||
|
||||
bool TMoverParameters::Attach(int ConnectNo, int ConnectToNr, TMoverParameters *ConnectTo,
|
||||
int CouplingType, bool Forced)
|
||||
bool TMoverParameters::Attach(int ConnectNo, int ConnectToNr, TMoverParameters *ConnectTo, int CouplingType, bool Forced)
|
||||
{ //łączenie do swojego sprzęgu (ConnectNo) pojazdu (ConnectTo) stroną (ConnectToNr)
|
||||
// Ra: zwykle wykonywane dwukrotnie, dla każdego pojazdu oddzielnie
|
||||
// Ra: trzeba by odróżnić wymóg dociśnięcia od uszkodzenia sprzęgu przy podczepianiu AI do
|
||||
// składu
|
||||
if (ConnectTo) // jeśli nie pusty
|
||||
{
|
||||
auto &coupler = Couplers[ ConnectNo ];
|
||||
if (ConnectToNr != 2)
|
||||
Couplers[ConnectNo].ConnectedNr = ConnectToNr; // 2=nic nie podłączone
|
||||
TCouplerType ct = ConnectTo->Couplers[Couplers[ConnectNo].ConnectedNr]
|
||||
.CouplerType; // typ sprzęgu podłączanego pojazdu
|
||||
Couplers[ConnectNo].Connected =
|
||||
ConnectTo; // tak podpiąć (do siebie) zawsze można, najwyżej będzie wirtualny
|
||||
CouplerDist(ConnectNo); // przeliczenie odległości pomiędzy sprzęgami
|
||||
coupler.ConnectedNr = ConnectToNr; // 2=nic nie podłączone
|
||||
coupler.Connected = ConnectTo; // tak podpiąć (do siebie) zawsze można, najwyżej będzie wirtualny
|
||||
CouplerDist( ConnectNo ); // przeliczenie odległości pomiędzy sprzęgami
|
||||
|
||||
if (CouplingType == ctrain_virtual)
|
||||
return false; // wirtualny więcej nic nie robi
|
||||
if (Forced ? true : ((Couplers[ConnectNo].CoupleDist <= dEpsilon) &&
|
||||
(Couplers[ConnectNo].CouplerType != NoCoupler) &&
|
||||
(Couplers[ConnectNo].CouplerType == ct)))
|
||||
|
||||
auto &othercoupler = ConnectTo->Couplers[ coupler.ConnectedNr ];
|
||||
if( ( Forced )
|
||||
|| ( ( coupler.CoupleDist <= dEpsilon )
|
||||
&& ( coupler.CouplerType != NoCoupler )
|
||||
&& ( coupler.CouplerType == othercoupler.CouplerType ) ) )
|
||||
{ // stykaja sie zderzaki i kompatybilne typy sprzegow, chyba że łączenie na starcie
|
||||
if (Couplers[ConnectNo].CouplingFlag ==
|
||||
ctrain_virtual) // jeśli wcześniej nie było połączone
|
||||
{ // ustalenie z której strony rysować sprzęg
|
||||
Couplers[ConnectNo].Render = true; // tego rysować
|
||||
ConnectTo->Couplers[Couplers[ConnectNo].ConnectedNr].Render = false; // a tego nie
|
||||
if( coupler.CouplingFlag == ctrain_virtual ) {
|
||||
// jeśli wcześniej nie było połączone, ustalenie z której strony rysować sprzęg
|
||||
coupler.Render = true; // tego rysować
|
||||
othercoupler.Render = false; // a tego nie
|
||||
};
|
||||
Couplers[ConnectNo].CouplingFlag = CouplingType; // ustawienie typu sprzęgu
|
||||
coupler.CouplingFlag = CouplingType; // ustawienie typu sprzęgu
|
||||
// if (CouplingType!=ctrain_virtual) //Ra: wirtualnego nie łączymy zwrotnie!
|
||||
//{//jeśli łączenie sprzęgiem niewirtualnym, ustawiamy połączenie zwrotne
|
||||
ConnectTo->Couplers[Couplers[ConnectNo].ConnectedNr].CouplingFlag = CouplingType;
|
||||
ConnectTo->Couplers[Couplers[ConnectNo].ConnectedNr].Connected = this;
|
||||
ConnectTo->Couplers[Couplers[ConnectNo].ConnectedNr].CoupleDist =
|
||||
Couplers[ConnectNo].CoupleDist;
|
||||
othercoupler.CouplingFlag = CouplingType;
|
||||
othercoupler.Connected = this;
|
||||
othercoupler.CoupleDist = coupler.CoupleDist;
|
||||
return true;
|
||||
//}
|
||||
// podłączenie nie udało się - jest wirtualne
|
||||
|
||||
33
Texture.cpp
33
Texture.cpp
@@ -480,6 +480,14 @@ opengl_texture::load_TGA() {
|
||||
return;
|
||||
}
|
||||
|
||||
downsize( GL_BGRA );
|
||||
if( ( data_width > Global::iMaxTextureSize ) || ( data_height > Global::iMaxTextureSize ) ) {
|
||||
// for non-square textures there's currently possibility the scaling routine will have to abort
|
||||
// before it gets all work done
|
||||
data_state = resource_state::failed;
|
||||
return;
|
||||
}
|
||||
|
||||
// TODO: add horizontal/vertical data flip, based on the descriptor (18th) header byte
|
||||
|
||||
// fill remaining data info
|
||||
@@ -656,6 +664,31 @@ opengl_texture::set_filtering() {
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
opengl_texture::downsize( GLuint const Format ) {
|
||||
|
||||
while( ( data_width > Global::iMaxTextureSize ) || ( data_height > Global::iMaxTextureSize ) ) {
|
||||
// scale down the base texture, if it's larger than allowed maximum
|
||||
// NOTE: scaling is uniform along both axes, meaning non-square textures can drop below the maximum
|
||||
// TODO: replace with proper scaling function once we have image middleware in place
|
||||
if( ( data_width < 2 ) || ( data_height < 2 ) ) {
|
||||
// can't go any smaller
|
||||
break;
|
||||
}
|
||||
|
||||
switch( Format ) {
|
||||
|
||||
case GL_RGB: { downsample< glm::tvec3<std::uint8_t> >( data_width, data_height, data.data() ); break; }
|
||||
case GL_BGRA:
|
||||
case GL_RGBA: { downsample< glm::tvec4<std::uint8_t> >( data_width, data_height, data.data() ); break; }
|
||||
default: { break; }
|
||||
}
|
||||
data_width /= 2;
|
||||
data_height /= 2;
|
||||
data.resize( data.size() / 4 ); // not strictly needed, but, eh
|
||||
};
|
||||
}
|
||||
|
||||
void
|
||||
texture_manager::Init() {
|
||||
}
|
||||
|
||||
58
Texture.h
58
Texture.h
@@ -46,6 +46,7 @@ private:
|
||||
void load_TEX();
|
||||
void load_TGA();
|
||||
void set_filtering();
|
||||
void downsize( GLuint const Format );
|
||||
|
||||
// members
|
||||
std::vector<char> data; // texture data
|
||||
@@ -113,3 +114,60 @@ private:
|
||||
index_map m_texturemappings;
|
||||
size_type m_activetexture{ 0 }; // last i.e. currently bound texture
|
||||
};
|
||||
|
||||
// reduces provided data image to half of original size, using basic 2x2 average
|
||||
template <typename _Colortype>
|
||||
void
|
||||
downsample( std::size_t const Width, std::size_t const Height, char *Imagedata ) {
|
||||
|
||||
_Colortype *destination = reinterpret_cast<_Colortype*>( Imagedata );
|
||||
_Colortype *sampler = reinterpret_cast<_Colortype*>( Imagedata );
|
||||
|
||||
_Colortype accumulator, color;
|
||||
/*
|
||||
_Colortype color;
|
||||
float component;
|
||||
*/
|
||||
for( size_t row = 0; row < Height; row += 2, sampler += Width ) { // column movement advances us down another row
|
||||
for( size_t column = 0; column < Width; column += 2, sampler += 2 ) {
|
||||
/*
|
||||
// straightforward, but won't work with byte data
|
||||
auto color = (
|
||||
*sampler
|
||||
+ *( sampler + 1 )
|
||||
+ *( sampler + Width )
|
||||
+ *( sampler + Width + 1 ) );
|
||||
color /= 4;
|
||||
*/
|
||||
// manual version of the above, but drops colour resolution to 6 bits
|
||||
accumulator = *sampler;
|
||||
accumulator /= 4;
|
||||
color = accumulator;
|
||||
accumulator = *(sampler + 1);
|
||||
accumulator /= 4;
|
||||
color += accumulator;
|
||||
accumulator = *(sampler + Width);
|
||||
accumulator /= 4;
|
||||
color += accumulator;
|
||||
accumulator = *(sampler + Width + 1);
|
||||
accumulator /= 4;
|
||||
color += accumulator;
|
||||
|
||||
*destination++ = color;
|
||||
/*
|
||||
// "full" 8bit resolution
|
||||
color = _Colortype(); component = 0;
|
||||
for( int idx = 0; idx < sizeof( _Colortype ); ++idx ) {
|
||||
|
||||
component = (
|
||||
(*sampler)[idx]
|
||||
+ ( *( sampler + 1 ) )[idx]
|
||||
+ ( *( sampler + Width ) )[idx]
|
||||
+ (*( sampler + Width + 1 ))[idx] );
|
||||
color[ idx ] = component /= 4;
|
||||
}
|
||||
*destination++ = color;
|
||||
*/
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
25
Train.cpp
25
Train.cpp
@@ -1827,7 +1827,7 @@ if
|
||||
if (tmp->MoverParameters->Attach(
|
||||
CouplNr, 2,
|
||||
tmp->MoverParameters->Couplers[CouplNr].Connected,
|
||||
tmp->MoverParameters->Couplers[CouplNr].CouplingFlag + ctrain_pneumatic))
|
||||
(tmp->MoverParameters->Couplers[CouplNr].CouplingFlag | ctrain_pneumatic)))
|
||||
{
|
||||
rsHiss.Play(1, DSBPLAY_LOOPING, true, tmp->GetPosition());
|
||||
DynamicObject->SetPneumatic(CouplNr != 0, true); // Ra: to mi się nie podoba !!!!
|
||||
@@ -1842,7 +1842,7 @@ if
|
||||
if (tmp->MoverParameters->Attach(
|
||||
CouplNr, 2,
|
||||
tmp->MoverParameters->Couplers[CouplNr].Connected,
|
||||
tmp->MoverParameters->Couplers[CouplNr].CouplingFlag + ctrain_scndpneumatic))
|
||||
(tmp->MoverParameters->Couplers[CouplNr].CouplingFlag | ctrain_scndpneumatic)))
|
||||
{
|
||||
// rsHiss.Play(1,DSBPLAY_LOOPING,true,tmp->GetPosition());
|
||||
dsbCouplerDetach->SetVolume(DSBVOLUME_MAX);
|
||||
@@ -1861,15 +1861,13 @@ if
|
||||
if (tmp->MoverParameters->Attach(
|
||||
CouplNr, 2,
|
||||
tmp->MoverParameters->Couplers[CouplNr].Connected,
|
||||
tmp->MoverParameters->Couplers[CouplNr].CouplingFlag +
|
||||
ctrain_controll))
|
||||
(tmp->MoverParameters->Couplers[CouplNr].CouplingFlag | ctrain_controll)))
|
||||
{
|
||||
dsbCouplerAttach->SetVolume(DSBVOLUME_MAX);
|
||||
dsbCouplerAttach->Play(0, 0, 0);
|
||||
}
|
||||
}
|
||||
else if (!TestFlag(tmp->MoverParameters->Couplers[CouplNr].CouplingFlag,
|
||||
ctrain_passenger)) // mostek
|
||||
else if (!TestFlag(tmp->MoverParameters->Couplers[CouplNr].CouplingFlag, ctrain_passenger)) // mostek
|
||||
{
|
||||
if ((tmp->MoverParameters->Couplers[CouplNr]
|
||||
.Connected->Couplers[CouplNr]
|
||||
@@ -1879,8 +1877,7 @@ if
|
||||
if (tmp->MoverParameters->Attach(
|
||||
CouplNr, 2,
|
||||
tmp->MoverParameters->Couplers[CouplNr].Connected,
|
||||
tmp->MoverParameters->Couplers[CouplNr].CouplingFlag +
|
||||
ctrain_passenger))
|
||||
(tmp->MoverParameters->Couplers[CouplNr].CouplingFlag | ctrain_passenger)))
|
||||
{
|
||||
// rsHiss.Play(1,DSBPLAY_LOOPING,true,tmp->GetPosition());
|
||||
dsbCouplerDetach->SetVolume(DSBVOLUME_MAX);
|
||||
@@ -1899,8 +1896,7 @@ if
|
||||
// odlegle wagony
|
||||
if (iCabn > 0)
|
||||
{
|
||||
if (!FreeFlyModeFlag) // tryb 'kabinowy' (pozwala również rozłączyć
|
||||
// sprzęgi zablokowane)
|
||||
if (!FreeFlyModeFlag) // tryb 'kabinowy' (pozwala również rozłączyć sprzęgi zablokowane)
|
||||
{
|
||||
if (DynamicObject->DettachStatus(iCabn - 1) < 0) // jeśli jest co odczepić
|
||||
if (DynamicObject->Dettach(iCabn - 1)) // iCab==1:przód,iCab==2:tył
|
||||
@@ -1913,15 +1909,12 @@ if
|
||||
{ // tryb freefly
|
||||
int CouplNr = -1;
|
||||
TDynamicObject *tmp;
|
||||
tmp = DynamicObject->ABuScanNearestObject(DynamicObject->GetTrack(), 1, 1500,
|
||||
CouplNr);
|
||||
tmp = DynamicObject->ABuScanNearestObject(DynamicObject->GetTrack(), 1, 1500, CouplNr);
|
||||
if (tmp == NULL)
|
||||
tmp = DynamicObject->ABuScanNearestObject(DynamicObject->GetTrack(), -1,
|
||||
1500, CouplNr);
|
||||
tmp = DynamicObject->ABuScanNearestObject(DynamicObject->GetTrack(), -1, 1500, CouplNr);
|
||||
if (tmp && (CouplNr != -1))
|
||||
{
|
||||
if ((tmp->MoverParameters->Couplers[CouplNr].CouplingFlag & ctrain_depot) ==
|
||||
0) // jeżeli sprzęg niezablokowany
|
||||
if ((tmp->MoverParameters->Couplers[CouplNr].CouplingFlag & ctrain_depot) == 0) // jeżeli sprzęg niezablokowany
|
||||
if (tmp->DettachStatus(CouplNr) < 0) // jeśli jest co odczepić i się da
|
||||
if (!tmp->Dettach(CouplNr))
|
||||
{ // dźwięk odczepiania
|
||||
|
||||
12
stdafx.h
12
stdafx.h
@@ -61,10 +61,20 @@
|
||||
#include <condition_variable>
|
||||
#include <typeinfo>
|
||||
|
||||
#ifdef NDEBUG
|
||||
#define EU07_BUILD_STATIC
|
||||
#endif
|
||||
|
||||
#ifdef EU07_BUILD_STATIC
|
||||
#define GLEW_STATIC
|
||||
#else
|
||||
#ifdef _WINDOWS
|
||||
#define GLFW_DLL
|
||||
#endif // _windows
|
||||
#endif // build_static
|
||||
#include "GL/glew.h"
|
||||
#ifdef _WINDOWS
|
||||
#include "GL/wglew.h"
|
||||
#define GLFW_DLL
|
||||
#endif
|
||||
#define GLFW_INCLUDE_GLU
|
||||
//m7todo: jest tu bo nie chcia³o mi siê wpychaæ do wszystkich plików
|
||||
|
||||
Reference in New Issue
Block a user