mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-07-22 17:29: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 "resource.h"
|
||||||
#include "uilayer.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" )
|
#pragma comment( lib, "glfw3dll.lib" )
|
||||||
|
#else
|
||||||
|
#pragma comment( lib, "glfw3.lib" )
|
||||||
|
#endif
|
||||||
#pragma comment( lib, "glew32.lib" )
|
#pragma comment( lib, "glew32.lib" )
|
||||||
|
#endif // build_static
|
||||||
#pragma comment( lib, "opengl32.lib" )
|
#pragma comment( lib, "opengl32.lib" )
|
||||||
#pragma comment( lib, "glu32.lib" )
|
#pragma comment( lib, "glu32.lib" )
|
||||||
#pragma comment( lib, "dsound.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)
|
double TMoverParameters::CouplerDist(int Coupler)
|
||||||
{ // obliczenie odległości pomiędzy sprzęgami (kula!)
|
{ // obliczenie odległości pomiędzy sprzęgami (kula!)
|
||||||
return Couplers[Coupler].CoupleDist =
|
Couplers[Coupler].CoupleDist =
|
||||||
Distance(Loc, Couplers[Coupler].Connected->Loc, Dim,
|
Distance(
|
||||||
Couplers[Coupler].Connected->Dim); // odległość pomiędzy sprzęgami (kula!)
|
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,
|
bool TMoverParameters::Attach(int ConnectNo, int ConnectToNr, TMoverParameters *ConnectTo, int CouplingType, bool Forced)
|
||||||
int CouplingType, bool Forced)
|
|
||||||
{ //łączenie do swojego sprzęgu (ConnectNo) pojazdu (ConnectTo) stroną (ConnectToNr)
|
{ //łączenie do swojego sprzęgu (ConnectNo) pojazdu (ConnectTo) stroną (ConnectToNr)
|
||||||
// Ra: zwykle wykonywane dwukrotnie, dla każdego pojazdu oddzielnie
|
// 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
|
// Ra: trzeba by odróżnić wymóg dociśnięcia od uszkodzenia sprzęgu przy podczepianiu AI do
|
||||||
// składu
|
// składu
|
||||||
if (ConnectTo) // jeśli nie pusty
|
if (ConnectTo) // jeśli nie pusty
|
||||||
{
|
{
|
||||||
|
auto &coupler = Couplers[ ConnectNo ];
|
||||||
if (ConnectToNr != 2)
|
if (ConnectToNr != 2)
|
||||||
Couplers[ConnectNo].ConnectedNr = ConnectToNr; // 2=nic nie podłączone
|
coupler.ConnectedNr = ConnectToNr; // 2=nic nie podłączone
|
||||||
TCouplerType ct = ConnectTo->Couplers[Couplers[ConnectNo].ConnectedNr]
|
coupler.Connected = ConnectTo; // tak podpiąć (do siebie) zawsze można, najwyżej będzie wirtualny
|
||||||
.CouplerType; // typ sprzęgu podłączanego pojazdu
|
CouplerDist( ConnectNo ); // przeliczenie odległości pomiędzy sprzęgami
|
||||||
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
|
|
||||||
if (CouplingType == ctrain_virtual)
|
if (CouplingType == ctrain_virtual)
|
||||||
return false; // wirtualny więcej nic nie robi
|
return false; // wirtualny więcej nic nie robi
|
||||||
if (Forced ? true : ((Couplers[ConnectNo].CoupleDist <= dEpsilon) &&
|
|
||||||
(Couplers[ConnectNo].CouplerType != NoCoupler) &&
|
auto &othercoupler = ConnectTo->Couplers[ coupler.ConnectedNr ];
|
||||||
(Couplers[ConnectNo].CouplerType == ct)))
|
if( ( Forced )
|
||||||
|
|| ( ( coupler.CoupleDist <= dEpsilon )
|
||||||
|
&& ( coupler.CouplerType != NoCoupler )
|
||||||
|
&& ( coupler.CouplerType == othercoupler.CouplerType ) ) )
|
||||||
{ // stykaja sie zderzaki i kompatybilne typy sprzegow, chyba że łączenie na starcie
|
{ // stykaja sie zderzaki i kompatybilne typy sprzegow, chyba że łączenie na starcie
|
||||||
if (Couplers[ConnectNo].CouplingFlag ==
|
if( coupler.CouplingFlag == ctrain_virtual ) {
|
||||||
ctrain_virtual) // jeśli wcześniej nie było połączone
|
// jeśli wcześniej nie było połączone, ustalenie z której strony rysować sprzęg
|
||||||
{ // ustalenie z której strony rysować sprzęg
|
coupler.Render = true; // tego rysować
|
||||||
Couplers[ConnectNo].Render = true; // tego rysować
|
othercoupler.Render = false; // a tego nie
|
||||||
ConnectTo->Couplers[Couplers[ConnectNo].ConnectedNr].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!
|
// if (CouplingType!=ctrain_virtual) //Ra: wirtualnego nie łączymy zwrotnie!
|
||||||
//{//jeśli łączenie sprzęgiem niewirtualnym, ustawiamy połączenie zwrotne
|
//{//jeśli łączenie sprzęgiem niewirtualnym, ustawiamy połączenie zwrotne
|
||||||
ConnectTo->Couplers[Couplers[ConnectNo].ConnectedNr].CouplingFlag = CouplingType;
|
othercoupler.CouplingFlag = CouplingType;
|
||||||
ConnectTo->Couplers[Couplers[ConnectNo].ConnectedNr].Connected = this;
|
othercoupler.Connected = this;
|
||||||
ConnectTo->Couplers[Couplers[ConnectNo].ConnectedNr].CoupleDist =
|
othercoupler.CoupleDist = coupler.CoupleDist;
|
||||||
Couplers[ConnectNo].CoupleDist;
|
|
||||||
return true;
|
return true;
|
||||||
//}
|
//}
|
||||||
// podłączenie nie udało się - jest wirtualne
|
// podłączenie nie udało się - jest wirtualne
|
||||||
|
|||||||
33
Texture.cpp
33
Texture.cpp
@@ -480,6 +480,14 @@ opengl_texture::load_TGA() {
|
|||||||
return;
|
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
|
// TODO: add horizontal/vertical data flip, based on the descriptor (18th) header byte
|
||||||
|
|
||||||
// fill remaining data info
|
// 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
|
void
|
||||||
texture_manager::Init() {
|
texture_manager::Init() {
|
||||||
}
|
}
|
||||||
|
|||||||
58
Texture.h
58
Texture.h
@@ -46,6 +46,7 @@ private:
|
|||||||
void load_TEX();
|
void load_TEX();
|
||||||
void load_TGA();
|
void load_TGA();
|
||||||
void set_filtering();
|
void set_filtering();
|
||||||
|
void downsize( GLuint const Format );
|
||||||
|
|
||||||
// members
|
// members
|
||||||
std::vector<char> data; // texture data
|
std::vector<char> data; // texture data
|
||||||
@@ -113,3 +114,60 @@ private:
|
|||||||
index_map m_texturemappings;
|
index_map m_texturemappings;
|
||||||
size_type m_activetexture{ 0 }; // last i.e. currently bound texture
|
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(
|
if (tmp->MoverParameters->Attach(
|
||||||
CouplNr, 2,
|
CouplNr, 2,
|
||||||
tmp->MoverParameters->Couplers[CouplNr].Connected,
|
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());
|
rsHiss.Play(1, DSBPLAY_LOOPING, true, tmp->GetPosition());
|
||||||
DynamicObject->SetPneumatic(CouplNr != 0, true); // Ra: to mi się nie podoba !!!!
|
DynamicObject->SetPneumatic(CouplNr != 0, true); // Ra: to mi się nie podoba !!!!
|
||||||
@@ -1842,7 +1842,7 @@ if
|
|||||||
if (tmp->MoverParameters->Attach(
|
if (tmp->MoverParameters->Attach(
|
||||||
CouplNr, 2,
|
CouplNr, 2,
|
||||||
tmp->MoverParameters->Couplers[CouplNr].Connected,
|
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());
|
// rsHiss.Play(1,DSBPLAY_LOOPING,true,tmp->GetPosition());
|
||||||
dsbCouplerDetach->SetVolume(DSBVOLUME_MAX);
|
dsbCouplerDetach->SetVolume(DSBVOLUME_MAX);
|
||||||
@@ -1861,15 +1861,13 @@ if
|
|||||||
if (tmp->MoverParameters->Attach(
|
if (tmp->MoverParameters->Attach(
|
||||||
CouplNr, 2,
|
CouplNr, 2,
|
||||||
tmp->MoverParameters->Couplers[CouplNr].Connected,
|
tmp->MoverParameters->Couplers[CouplNr].Connected,
|
||||||
tmp->MoverParameters->Couplers[CouplNr].CouplingFlag +
|
(tmp->MoverParameters->Couplers[CouplNr].CouplingFlag | ctrain_controll)))
|
||||||
ctrain_controll))
|
|
||||||
{
|
{
|
||||||
dsbCouplerAttach->SetVolume(DSBVOLUME_MAX);
|
dsbCouplerAttach->SetVolume(DSBVOLUME_MAX);
|
||||||
dsbCouplerAttach->Play(0, 0, 0);
|
dsbCouplerAttach->Play(0, 0, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (!TestFlag(tmp->MoverParameters->Couplers[CouplNr].CouplingFlag,
|
else if (!TestFlag(tmp->MoverParameters->Couplers[CouplNr].CouplingFlag, ctrain_passenger)) // mostek
|
||||||
ctrain_passenger)) // mostek
|
|
||||||
{
|
{
|
||||||
if ((tmp->MoverParameters->Couplers[CouplNr]
|
if ((tmp->MoverParameters->Couplers[CouplNr]
|
||||||
.Connected->Couplers[CouplNr]
|
.Connected->Couplers[CouplNr]
|
||||||
@@ -1879,8 +1877,7 @@ if
|
|||||||
if (tmp->MoverParameters->Attach(
|
if (tmp->MoverParameters->Attach(
|
||||||
CouplNr, 2,
|
CouplNr, 2,
|
||||||
tmp->MoverParameters->Couplers[CouplNr].Connected,
|
tmp->MoverParameters->Couplers[CouplNr].Connected,
|
||||||
tmp->MoverParameters->Couplers[CouplNr].CouplingFlag +
|
(tmp->MoverParameters->Couplers[CouplNr].CouplingFlag | ctrain_passenger)))
|
||||||
ctrain_passenger))
|
|
||||||
{
|
{
|
||||||
// rsHiss.Play(1,DSBPLAY_LOOPING,true,tmp->GetPosition());
|
// rsHiss.Play(1,DSBPLAY_LOOPING,true,tmp->GetPosition());
|
||||||
dsbCouplerDetach->SetVolume(DSBVOLUME_MAX);
|
dsbCouplerDetach->SetVolume(DSBVOLUME_MAX);
|
||||||
@@ -1899,8 +1896,7 @@ if
|
|||||||
// odlegle wagony
|
// odlegle wagony
|
||||||
if (iCabn > 0)
|
if (iCabn > 0)
|
||||||
{
|
{
|
||||||
if (!FreeFlyModeFlag) // tryb 'kabinowy' (pozwala również rozłączyć
|
if (!FreeFlyModeFlag) // tryb 'kabinowy' (pozwala również rozłączyć sprzęgi zablokowane)
|
||||||
// sprzęgi zablokowane)
|
|
||||||
{
|
{
|
||||||
if (DynamicObject->DettachStatus(iCabn - 1) < 0) // jeśli jest co odczepić
|
if (DynamicObject->DettachStatus(iCabn - 1) < 0) // jeśli jest co odczepić
|
||||||
if (DynamicObject->Dettach(iCabn - 1)) // iCab==1:przód,iCab==2:tył
|
if (DynamicObject->Dettach(iCabn - 1)) // iCab==1:przód,iCab==2:tył
|
||||||
@@ -1913,15 +1909,12 @@ if
|
|||||||
{ // tryb freefly
|
{ // tryb freefly
|
||||||
int CouplNr = -1;
|
int CouplNr = -1;
|
||||||
TDynamicObject *tmp;
|
TDynamicObject *tmp;
|
||||||
tmp = DynamicObject->ABuScanNearestObject(DynamicObject->GetTrack(), 1, 1500,
|
tmp = DynamicObject->ABuScanNearestObject(DynamicObject->GetTrack(), 1, 1500, CouplNr);
|
||||||
CouplNr);
|
|
||||||
if (tmp == NULL)
|
if (tmp == NULL)
|
||||||
tmp = DynamicObject->ABuScanNearestObject(DynamicObject->GetTrack(), -1,
|
tmp = DynamicObject->ABuScanNearestObject(DynamicObject->GetTrack(), -1, 1500, CouplNr);
|
||||||
1500, CouplNr);
|
|
||||||
if (tmp && (CouplNr != -1))
|
if (tmp && (CouplNr != -1))
|
||||||
{
|
{
|
||||||
if ((tmp->MoverParameters->Couplers[CouplNr].CouplingFlag & ctrain_depot) ==
|
if ((tmp->MoverParameters->Couplers[CouplNr].CouplingFlag & ctrain_depot) == 0) // jeżeli sprzęg niezablokowany
|
||||||
0) // jeżeli sprzęg niezablokowany
|
|
||||||
if (tmp->DettachStatus(CouplNr) < 0) // jeśli jest co odczepić i się da
|
if (tmp->DettachStatus(CouplNr) < 0) // jeśli jest co odczepić i się da
|
||||||
if (!tmp->Dettach(CouplNr))
|
if (!tmp->Dettach(CouplNr))
|
||||||
{ // dźwięk odczepiania
|
{ // dźwięk odczepiania
|
||||||
|
|||||||
12
stdafx.h
12
stdafx.h
@@ -61,10 +61,20 @@
|
|||||||
#include <condition_variable>
|
#include <condition_variable>
|
||||||
#include <typeinfo>
|
#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"
|
#include "GL/glew.h"
|
||||||
#ifdef _WINDOWS
|
#ifdef _WINDOWS
|
||||||
#include "GL/wglew.h"
|
#include "GL/wglew.h"
|
||||||
#define GLFW_DLL
|
|
||||||
#endif
|
#endif
|
||||||
#define GLFW_INCLUDE_GLU
|
#define GLFW_INCLUDE_GLU
|
||||||
//m7todo: jest tu bo nie chcia³o mi siê wpychaæ do wszystkich plików
|
//m7todo: jest tu bo nie chcia³o mi siê wpychaæ do wszystkich plików
|
||||||
|
|||||||
Reference in New Issue
Block a user