Skip to content

Commit 9c1adc1

Browse files
author
jcnossen
committed
-most camera controllers use mouseScale value, made a bunch of camera movement actions dependent on mouseScale.
-Fixed sound playing in windows (it stopped after maxSounds were played). I'm not sure why it didn't work in the first place though. -Added CR_ENUM_MEMBER macro for member values with an enumerated type. git-svn-id: https://spring.clan-sy.com/svn/spring/trunk@551 37977431-3df6-0310-b722-df95706aa16b
1 parent e5404e8 commit 9c1adc1

File tree

7 files changed

+50
-28
lines changed

7 files changed

+50
-28
lines changed

rts/Game/CameraController.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ extern Uint8 *keys;
1818

1919
CCameraController::CCameraController(void)
2020
{
21+
mouseScale = atof(configHandler.GetString("FPSMouseScale", DEFAULT_MOUSE_SCALE).c_str());
2122
}
2223

2324
CCameraController::~CCameraController(void)
@@ -31,7 +32,6 @@ CCameraController::~CCameraController(void)
3132
CFPSController::CFPSController()
3233
: pos(2000,70,1800)
3334
{
34-
mouseScale = atof(configHandler.GetString("FPSMouseScale", DEFAULT_MOUSE_SCALE).c_str());
3535
}
3636

3737
void CFPSController::KeyMove(float3 move)
@@ -124,7 +124,7 @@ void COverheadController::KeyMove(float3 move)
124124

125125
void COverheadController::MouseMove(float3 move)
126126
{
127-
float pixelsize=tan(camera->fov/180/2*PI)*2/gu->screeny*height*2;
127+
float pixelsize=100*mouseScale*tan(camera->fov/180/2*PI)*2/gu->screeny*height*2;
128128
pos.x+=move.x*pixelsize*(1+keys[SDLK_LSHIFT]*3);
129129
pos.z+=move.y*pixelsize*(1+keys[SDLK_LSHIFT]*3);
130130
}
@@ -137,11 +137,11 @@ void COverheadController::ScreenEdgeMove(float3 move)
137137
void COverheadController::MouseWheelMove(float move)
138138
{
139139
if (keys[SDLK_LCTRL]) {
140-
zscale *= 1+move*0.002;
140+
zscale *= 1+move * mouseScale;
141141
if (zscale < 0.05) zscale = 0.05f;
142142
if (zscale > 10) zscale = 10;
143143
} else
144-
height*=1+move*0.001;
144+
height*=1+move * mouseScale*0.7;
145145
}
146146

147147
float3 COverheadController::GetPos()

rts/Game/CameraController.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ class CCameraController
1818
virtual void SetPos(float3 newPos)=0;
1919
virtual float3 SwitchFrom()=0; //return pos that to send to new controllers SetPos
2020
virtual void SwitchTo()=0;
21+
22+
float mouseScale;
2123
};
2224

2325
class CFPSController : public CCameraController
@@ -41,8 +43,6 @@ class CFPSController : public CCameraController
4143
float oldHeight;
4244

4345
float3 dir;
44-
45-
float mouseScale;
4646
};
4747

4848
class COverheadController : public CCameraController
@@ -109,8 +109,6 @@ class CRotOverheadController : public CCameraController
109109
float oldHeight;
110110

111111
float3 dir;
112-
113-
float mouseScale;
114112
};
115113

116114
#endif // __CAMERA_CONTROLLER_H__

rts/Sim/Misc/Feature.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ void CFeature::Initialize (const float3& pos,FeatureDef* def,short int heading,i
7474
{
7575
this->def=def;
7676
createdFromUnit=fromUnit;
77+
this->pos=pos;
7778
this->allyteam=allyteam;
7879
this->pos.CheckInBounds();
7980
this->heading=heading;

rts/Sim/Units/COB/CobInstance.cpp

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -954,15 +954,6 @@ void CCobInstance::SetUnitVal(int val, int param)
954954
case VETERAN_LEVEL:
955955
unit->experience=param*0.01f;
956956
break;
957-
case CURRENT_SPEED:
958-
if (param==0)
959-
unit->speed=ZeroVector;
960-
else {
961-
float cur=unit->speed.SqLength();
962-
if (cur>0.001)
963-
unit->speed *= (param*(1.0f/SCALE))/sqrtf(cur); // calculate by what value the speed should be multiplied with to get it to length=param/SCALE
964-
}
965-
break;
966957
}
967958
#endif
968959
}

rts/System/Sound.cpp

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,19 @@ CSound::CSound()
3939
noSound = true;
4040
return;
4141
}
42+
43+
// Generate sound sources
4244
Sources = new ALuint[maxSounds];
45+
for (int a=0;a<maxSounds;a++) Sources[a]=0;
4346
}
4447

4548
CSound::~CSound()
4649
{
4750
LoadedFiles.clear();
48-
alDeleteSources(maxSounds,Sources);
49-
if (!noSound)
51+
if (!noSound) {
52+
alDeleteSources(maxSounds,Sources);
5053
delete[] Sources;
54+
}
5155
for (std::vector<ALuint>::iterator it = Buffers.begin(); it != Buffers.end(); it++)
5256
alDeleteBuffers(1,&(*it));
5357
Buffers.clear();
@@ -78,28 +82,43 @@ void CSound::PlaySound(int id,const float3& p,float volume)
7882
return;
7983
ALuint source;
8084
alGenSources(1,&source);
85+
86+
if (alGetError() != AL_NO_ERROR) {
87+
(*info) << "error generating OpenAL sound source";
88+
return;
89+
}
90+
91+
if (Sources[cur])
92+
alDeleteSources(1,&Sources[cur]);
93+
Sources[cur++] = source;
94+
if (cur == maxSounds)
95+
cur = 0;
96+
8197
alSourcei(source, AL_BUFFER, id);
8298
alSourcef(source, AL_PITCH, 1.0f );
8399
alSourcef(source, AL_GAIN, volume );
84100
alSource3f(source, AL_POSITION, p.x/(gs->mapx*SQUARE_SIZE),p.y/(gs->mapy*SQUARE_SIZE),p.z/(p.maxzpos));
85101
alSource3f(source, AL_VELOCITY, 0.0f,0.0f,0.0f);
86102
alSourcei(source, AL_LOOPING, false);
87-
Enqueue(source);
88103
alSourcePlay(source);
89104
}
90105

91-
void CSound::Enqueue(ALuint src)
92-
{
93-
alDeleteSources(1,&Sources[cur]);
94-
Sources[cur++] = src;
95-
if (cur == maxSounds)
96-
cur = 0;
97-
}
98-
99106
void CSound::Update()
100107
{
101108
if (noSound)
102109
return;
110+
111+
for (int a=0;a<maxSounds;a++) {
112+
if (Sources[a]) {
113+
ALint state;
114+
alGetSourcei(Sources[a],AL_SOURCE_STATE, &state);
115+
if (state == AL_STOPPED) {
116+
alDeleteSources(1,&Sources[a]);
117+
Sources[a]=0;
118+
}
119+
}
120+
}
121+
103122
UpdateListener();
104123
}
105124

rts/System/creg/ClassReg.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,8 @@ namespace creg {
9494
// Macro to register a member within the CR_BIND_MEMBERS macro - the offset is a bit weird to prevent compiler warnings
9595
#define CR_MEMBER(Member) \
9696
class_->AddMember ( #Member, creg::GetType (null->Member), (unsigned int)(((char*)&null->Member)-((char*)0)))
97+
#define CR_ENUM_MEMBER(Member) \
98+
class_->AddMember ( #Member, IType::CreateEnumeratedType(sizeof(null->Member)), (unsigned int)(((char*)&null->Member)-((char*)0)))
9799

98100
// Base object class - all objects should derive from this if they should be referencable by pointers
99101
class Object
@@ -152,6 +154,7 @@ namespace creg {
152154
static IType* CreateStringType ();
153155
static IType* CreatePointerToObjType (Class *objectType);
154156
static IType* CreateStaticArrayType (IType *elemType, unsigned int size);
157+
static IType* CreateEnumeratedType (size_t size);
155158
};
156159

157160
struct Iterator; // Undefined Iterator struct to denote a container iterator

rts/System/creg/VarTypes.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,16 @@ IType* IType::CreateStaticArrayType (IType *elemType, unsigned int size)
2929
return new StaticArrayType (elemType, size);
3030
}
3131

32+
IType* IType::CreateEnumeratedType (size_t size)
33+
{
34+
switch (size) {
35+
case 1: return new BasicType (crUChar);
36+
case 2: return new BasicType (crUShort);
37+
case 4: return new BasicType (crUInt);
38+
}
39+
return 0;
40+
}
41+
3242

3343
// container type
3444

0 commit comments

Comments
 (0)