Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
View | Details | Raw Unified | Return to bug 434148 | Differences between
and this patch

Collapse All | Expand All

(-)data/skins/simple/menus/AssignControl (-2 / +2 lines)
Lines 46-52 Link Here
46
image = white.png
46
image = white.png
47
color = 0.172, 0.161, 0.169
47
color = 0.172, 0.161, 0.169
48
alpha = 0.7
48
alpha = 0.7
49
left = 0.2
49
left = 0.1
50
right = 0.2
50
right = 0.1
51
top = 0.48
51
top = 0.48
52
height = 0.04
52
height = 0.04
(-)data/skins/simple/menus/GuiControls (-3 / +3 lines)
Lines 82-88 Link Here
82
onselect = controledit.string:gui_select:0
82
onselect = controledit.string:gui_select:0
83
onmoveleft = widget-01d
83
onmoveleft = widget-01d
84
onmoveright = widget-01c
84
onmoveright = widget-01c
85
onmoveup = widget-13b
85
onmoveup = widget-08b
86
onmovedown = widget-02b
86
onmovedown = widget-02b
87
onfocus = widget-01b.sat:0.56
87
onfocus = widget-01b.sat:0.56
88
onblur = widget-01b.sat:0.0
88
onblur = widget-01b.sat:0.0
Lines 101-107 Link Here
101
onselect = controledit.string:gui_select:1
101
onselect = controledit.string:gui_select:1
102
onmoveleft = widget-01b
102
onmoveleft = widget-01b
103
onmoveright = widget-01d
103
onmoveright = widget-01d
104
onmoveup = widget-13b
104
onmoveup = widget-08b
105
onmovedown = widget-02c
105
onmovedown = widget-02c
106
onfocus = widget-01c.sat:0.56
106
onfocus = widget-01c.sat:0.56
107
onblur = widget-01c.sat:0.0
107
onblur = widget-01c.sat:0.0
Lines 120-126 Link Here
120
onselect = controledit.string:gui_select:2
120
onselect = controledit.string:gui_select:2
121
onmoveleft = widget-01c
121
onmoveleft = widget-01c
122
onmoveright = widget-01b
122
onmoveright = widget-01b
123
onmoveup = widget-13b
123
onmoveup = widget-08b
124
onmovedown = widget-02d
124
onmovedown = widget-02d
125
onfocus = widget-01d.sat:0.56
125
onfocus = widget-01d.sat:0.56
126
onblur = widget-01d.sat:0.0
126
onblur = widget-01d.sat:0.0
(-)data/skins/simple/menus/InGameMain (-4 / +4 lines)
Lines 44-53 Link Here
44
44
45
45
46
[ widget-01 ]
46
[ widget-01 ]
47
text = Return to Game
47
text = Continue
48
fontsize = 0.035
48
fontsize = 0.035
49
align = left
49
align = left
50
tip = Leave the menu and unpause the game.
50
tip = Leave the menu and continue the game.
51
onselect = ReturnToGame
51
onselect = ReturnToGame
52
onmoveup = widget-05
52
onmoveup = widget-05
53
onmovedown = widget-02
53
onmovedown = widget-02
Lines 72-78 Link Here
72
72
73
73
74
[ widget-02 ]
74
[ widget-02 ]
75
text = Restart Game
75
text = Restart
76
fontsize = 0.035
76
fontsize = 0.035
77
align = left
77
align = left
78
tip = Restart this game using the same car and track settings.
78
tip = Restart this game using the same car and track settings.
Lines 100-106 Link Here
100
100
101
101
102
[ widget-03 ]
102
[ widget-03 ]
103
text = Leave Game
103
text = Abort
104
fontsize = 0.035
104
fontsize = 0.035
105
align = left
105
align = left
106
tip = Leave game and return to the Main menu.
106
tip = Leave game and return to the Main menu.
(-)data/skins/simple/menus/InputDevice (-2 / +2 lines)
Lines 82-88 Link Here
82
onselect = joystick.type.prev
82
onselect = joystick.type.prev
83
onmoveleft = joystick.type.prev
83
onmoveleft = joystick.type.prev
84
onmoveright = joystick.type.next
84
onmoveright = joystick.type.next
85
onmoveup = widget-13b
85
onmoveup = widget-11b
86
onmovedown = widget-02b
86
onmovedown = widget-02b
87
onfocus = widget-01b.alpha:1 widget-01c.alpha:1 widget-01d.sat:0.56
87
onfocus = widget-01b.alpha:1 widget-01c.alpha:1 widget-01d.sat:0.56
88
onblur = widget-01b.alpha:0 widget-01c.alpha:0 widget-01d.sat:0.0
88
onblur = widget-01b.alpha:0 widget-01c.alpha:0 widget-01d.sat:0.0
Lines 102-108 Link Here
102
onselect = joystick.type.next
102
onselect = joystick.type.next
103
onmoveleft = joystick.type.prev
103
onmoveleft = joystick.type.prev
104
onmoveright = joystick.type.next
104
onmoveright = joystick.type.next
105
onmoveup = widget-13b
105
onmoveup = widget-11b
106
onmovedown = widget-02b
106
onmovedown = widget-02b
107
onfocus = widget-01b.alpha:1 widget-01c.alpha:1 widget-01d.sat:0.56
107
onfocus = widget-01b.alpha:1 widget-01c.alpha:1 widget-01d.sat:0.56
108
onblur = widget-01b.alpha:0 widget-01c.alpha:0 widget-01d.sat:0.0
108
onblur = widget-01b.alpha:0 widget-01c.alpha:0 widget-01d.sat:0.0
(-)data/skins/simple/menus/SingleRace (-1 / +1 lines)
Lines 860-866 Link Here
860
onmoveleft = game.vehicle_damage.prev
860
onmoveleft = game.vehicle_damage.prev
861
onmoveright = game.vehicle_damage.next
861
onmoveright = game.vehicle_damage.next
862
onmoveup = widget-14b
862
onmoveup = widget-14b
863
onmovedown = widget-16
863
onmovedown = widget-16b
864
onfocus = widget-15b.alpha:1 widget-15c.alpha:1 widget-15d.sat:0.56
864
onfocus = widget-15b.alpha:1 widget-15c.alpha:1 widget-15d.sat:0.56
865
onblur = widget-15b.alpha:0 widget-15c.alpha:0 widget-15d.sat:0.0
865
onblur = widget-15b.alpha:0 widget-15c.alpha:0 widget-15d.sat:0.0
866
focus = false
866
focus = false
(-)src/camera.h (-1 / +1 lines)
Lines 16-22 Link Here
16
16
17
	const std::string & GetName() const { return name; }
17
	const std::string & GetName() const { return name; }
18
18
19
	void SetFOV(float value) { fov = std::max(40.0f, std::min(160.0f, value)); }
19
	void SetFOV(float value) { fov = std::max(0.0f, std::min(120.0f, value)); }
20
20
21
	float GetFOV() const { return fov; }
21
	float GetFOV() const { return fov; }
22
22
(-)src/carcontrolmap_local.cpp (-13 / +33 lines)
Lines 830-845 Link Here
830
	keycodes["y"] = SDLK_y;
830
	keycodes["y"] = SDLK_y;
831
	keycodes["z"] = SDLK_z;
831
	keycodes["z"] = SDLK_z;
832
	keycodes["DELETE"] = SDLK_DELETE;
832
	keycodes["DELETE"] = SDLK_DELETE;
833
	keycodes["KP0"] = SDLK_KP_0;
834
	keycodes["KP1"] = SDLK_KP_1;
835
	keycodes["KP2"] = SDLK_KP_2;
836
	keycodes["KP3"] = SDLK_KP_3;
837
	keycodes["KP4"] = SDLK_KP_4;
838
	keycodes["KP5"] = SDLK_KP_5;
839
	keycodes["KP6"] = SDLK_KP_6;
840
	keycodes["KP7"] = SDLK_KP_7;
841
	keycodes["KP8"] = SDLK_KP_8;
842
	keycodes["KP9"] = SDLK_KP_9;
843
	keycodes["KP_PERIOD"] = SDLK_KP_PERIOD;
833
	keycodes["KP_PERIOD"] = SDLK_KP_PERIOD;
844
	keycodes["KP_DIVIDE"] = SDLK_KP_DIVIDE;
834
	keycodes["KP_DIVIDE"] = SDLK_KP_DIVIDE;
845
	keycodes["KP_MULTIPLY"] = SDLK_KP_MULTIPLY;
835
	keycodes["KP_MULTIPLY"] = SDLK_KP_MULTIPLY;
Lines 872-891 Link Here
872
	keycodes["F14"] = SDLK_F14;
862
	keycodes["F14"] = SDLK_F14;
873
	keycodes["F15"] = SDLK_F15;
863
	keycodes["F15"] = SDLK_F15;
874
	keycodes["MENU"] = SDLK_MENU;
864
	keycodes["MENU"] = SDLK_MENU;
875
	keycodes["APPLICATION"] = SDLK_APPLICATION;
876
	keycodes["NUMLOCK"] = SDLK_NUMLOCKCLEAR;
877
	keycodes["CAPSLOCK"] = SDLK_CAPSLOCK;
865
	keycodes["CAPSLOCK"] = SDLK_CAPSLOCK;
878
	keycodes["SCROLLLOCK"] = SDLK_SCROLLLOCK;
879
	keycodes["RSHIFT"] = SDLK_RSHIFT;
866
	keycodes["RSHIFT"] = SDLK_RSHIFT;
880
	keycodes["LSHIFT"] = SDLK_LSHIFT;
867
	keycodes["LSHIFT"] = SDLK_LSHIFT;
881
	keycodes["RCTRL"] = SDLK_RCTRL;
868
	keycodes["RCTRL"] = SDLK_RCTRL;
882
	keycodes["LCTRL"] = SDLK_LCTRL;
869
	keycodes["LCTRL"] = SDLK_LCTRL;
883
	keycodes["RALT"] = SDLK_RALT;
870
	keycodes["RALT"] = SDLK_RALT;
884
	keycodes["LALT"] = SDLK_LALT;
871
	keycodes["LALT"] = SDLK_LALT;
872
#if SDL_VERSION_ATLEAST(2,0,0)
873
	keycodes["KP0"] = SDLK_KP_0;
874
	keycodes["KP1"] = SDLK_KP_1;
875
	keycodes["KP2"] = SDLK_KP_2;
876
	keycodes["KP3"] = SDLK_KP_3;
877
	keycodes["KP4"] = SDLK_KP_4;
878
	keycodes["KP5"] = SDLK_KP_5;
879
	keycodes["KP6"] = SDLK_KP_6;
880
	keycodes["KP7"] = SDLK_KP_7;
881
	keycodes["KP8"] = SDLK_KP_8;
882
	keycodes["KP9"] = SDLK_KP_9;
883
	keycodes["COMPOSE"] = SDLK_APPLICATION;
884
	keycodes["NUMLOCK"] = SDLK_NUMLOCKCLEAR;
885
	keycodes["SCROLLLOCK"] = SDLK_SCROLLLOCK;
885
	keycodes["RMETA"] = SDLK_RGUI;
886
	keycodes["RMETA"] = SDLK_RGUI;
886
	keycodes["LMETA"] = SDLK_LGUI;
887
	keycodes["LMETA"] = SDLK_LGUI;
887
	keycodes["LSUPER"] = SDLK_LGUI;
888
	keycodes["LSUPER"] = SDLK_LGUI;
888
	keycodes["RSUPER"] = SDLK_RGUI;
889
	keycodes["RSUPER"] = SDLK_RGUI;
890
#else
891
	keycodes["KP0"] = SDLK_KP0;
892
	keycodes["KP1"] = SDLK_KP1;
893
	keycodes["KP2"] = SDLK_KP2;
894
	keycodes["KP3"] = SDLK_KP3;
895
	keycodes["KP4"] = SDLK_KP4;
896
	keycodes["KP5"] = SDLK_KP5;
897
	keycodes["KP6"] = SDLK_KP6;
898
	keycodes["KP7"] = SDLK_KP7;
899
	keycodes["KP8"] = SDLK_KP8;
900
	keycodes["KP9"] = SDLK_KP9;
901
	keycodes["COMPOSE"] = SDLK_COMPOSE;
902
	keycodes["NUMLOCK"] = SDLK_NUMLOCK;
903
	keycodes["SCROLLLOCK"] = SDLK_SCROLLOCK;
904
	keycodes["LMETA"] = SDLK_LMETA;
905
	keycodes["RMETA"] = SDLK_RMETA;
906
	keycodes["LSUPER"] = SDLK_LSUPER;
907
	keycodes["RSUPER"] = SDLK_RSUPER;
908
#endif
889
	return keycodes;
909
	return keycodes;
890
}
910
}
891
911
(-)src/game.cpp (-39 / +36 lines)
Lines 324-333 Link Here
324
324
325
	info_output << "Shutting down..." << std::endl;
325
	info_output << "Shutting down..." << std::endl;
326
326
327
	// Stop the sound thread.
328
	if (sound.Enabled())
329
		sound.Pause(true);
330
331
	LeaveGame();
327
	LeaveGame();
332
328
333
	// Save settings first incase later deinits cause crashes.
329
	// Save settings first incase later deinits cause crashes.
Lines 499-514 Link Here
499
	}
495
	}
500
496
501
	// Connect game actions to gui options
497
	// Connect game actions to gui options
502
	set_car_name.connect(gui.GetOption("game.car").signal_val);
498
	BindActionsToGUI();
503
	set_car_paint.connect(gui.GetOption("game.car_paint").signal_val);
504
	set_car_color_hue.connect(gui.GetOption("game.car_color_hue").signal_val);
505
	set_car_color_sat.connect(gui.GetOption("game.car_color_sat").signal_val);
506
	set_car_color_val.connect(gui.GetOption("game.car_color_val").signal_val);
507
	set_car_ai_type.connect(gui.GetOption("game.ai_type").signal_val);
508
	set_car_ai_level.connect(gui.GetOption("game.ai_level").signal_val);
509
	set_cars_num.connect(gui.GetOption("game.cars_num").signal_val);
510
	set_track_image.connect(gui.GetOption("game.track").signal_val);
511
	set_control.connect(gui.GetOption("controledit.string").signal_val);
512
499
513
	// Set options from game settings.
500
	// Set options from game settings.
514
	std::map<std::string, std::string> optionmap;
501
	std::map<std::string, std::string> optionmap;
Lines 531-537 Link Here
531
	if (sound.Init(2048, info_output, error_output))
518
	if (sound.Init(2048, info_output, error_output))
532
	{
519
	{
533
		sound.SetVolume(settings.GetSoundVolume());
520
		sound.SetVolume(settings.GetSoundVolume());
534
		//sound.Pause(false);
535
		content.setSound(sound.GetDeviceInfo());
521
		content.setSound(sound.GetDeviceInfo());
536
	}
522
	}
537
	else
523
	else
Lines 932-953 Link Here
932
	if (sound.Enabled())
918
	if (sound.Enabled())
933
	{
919
	{
934
		bool pause_sound = pause || gui.Active();
920
		bool pause_sound = pause || gui.Active();
935
		sound.Pause(pause_sound);
921
		PROFILER.beginBlock("sound");
936
		if (!pause_sound)
922
		MATHVECTOR <float, 3> pos;
937
		{
923
		QUATERNION <float> rot;
938
			PROFILER.beginBlock("sound");
924
		if (active_camera)
939
			MATHVECTOR <float, 3> pos;
925
		{
940
			QUATERNION <float> rot;
926
			pos = active_camera->GetPosition();
941
			if (active_camera)
927
			rot = active_camera->GetOrientation();
942
			{
928
		}
943
				pos = active_camera->GetPosition();
929
		sound.SetListenerPosition(pos[0], pos[1], pos[2]);
944
				rot = active_camera->GetOrientation();
930
		sound.SetListenerRotation(rot[0], rot[1], rot[2], rot[3]);
945
			}
931
		sound.Update(pause_sound);
946
			sound.SetListenerPosition(pos[0], pos[1], pos[2]);
932
		PROFILER.endBlock("sound");
947
			sound.SetListenerRotation(rot[0], rot[1], rot[2], rot[3]);
948
			sound.Update();
949
			PROFILER.endBlock("sound");
950
		}
951
	}
933
	}
952
934
953
	//PROFILER.beginBlock("force-feedback");
935
	//PROFILER.beginBlock("force-feedback");
Lines 1798-1806 Link Here
1798
	// get car start position marker for camera setup
1780
	// get car start position marker for camera setup
1799
	MATHVECTOR<float, 3> car_pos = track.GetStart(0).first;
1781
	MATHVECTOR<float, 3> car_pos = track.GetStart(0).first;
1800
1782
1801
	// car setup
1783
	// clear previous car
1802
	cars.clear();
1784
	cars.clear();
1803
1785
1786
	// remove previous car sounds
1787
	sound.Update(true);
1788
1804
	if (LoadCar(
1789
	if (LoadCar(
1805
		cars_name[car_edit_id],
1790
		cars_name[car_edit_id],
1806
		cars_paint[car_edit_id],
1791
		cars_paint[car_edit_id],
Lines 1808-1821 Link Here
1808
		car_pos, track.GetStart(0).second,
1793
		car_pos, track.GetStart(0).second,
1809
		true, false))
1794
		true, false))
1810
	{
1795
	{
1811
		// update car
1796
		// set car
1812
		CAR & car = cars.back();
1797
		CAR & car = cars.back();
1813
		dynamics.update(timestep);
1798
		dynamics.update(timestep);
1814
		car.Update(timestep);
1799
		car.Update(timestep);
1815
1800
1816
		// process car sound sources
1801
		// add car sounds
1817
		// should they be loaded for garage car in the first place?
1802
		sound.Update(true);
1818
		sound.Update();
1819
1803
1820
		// use car shape center for camera setup
1804
		// use car shape center for camera setup
1821
		car_pos = car.GetPosition();
1805
		car_pos = car.GetPosition();
Lines 1958-1964 Link Here
1958
	}
1942
	}
1959
1943
1960
	if (numreplays == 0)
1944
	if (numreplays == 0)
1961
		replaylist.push_back(std::make_pair("", "None"));
1945
		replaylist.push_back(std::make_pair("none", "None"));
1962
1946
1963
	settings.SetSelectedReplay(replaylist.begin()->first);
1947
	settings.SetSelectedReplay(replaylist.begin()->first);
1964
}
1948
}
Lines 2411-2416 Link Here
2411
2395
2412
	track.Clear();
2396
	track.Clear();
2413
	cars.clear();
2397
	cars.clear();
2398
	sound.Update(true);
2414
	hud.SetVisible(false);
2399
	hud.SetVisible(false);
2415
	inputgraph.Hide();
2400
	inputgraph.Hide();
2416
	trackmap.Unload();
2401
	trackmap.Unload();
Lines 2419-2425 Link Here
2419
	pause = false;
2404
	pause = false;
2420
	race_laps = 0;
2405
	race_laps = 0;
2421
	tire_smoke.Clear();
2406
	tire_smoke.Clear();
2422
	sound.Update();
2423
}
2407
}
2424
2408
2425
void GAME::StartPractice()
2409
void GAME::StartPractice()
Lines 2473-2479 Link Here
2473
2457
2474
void GAME::StartReplay()
2458
void GAME::StartReplay()
2475
{
2459
{
2476
	if (!settings.GetSelectedReplay().empty() && !NewGame(true))
2460
	if (settings.GetSelectedReplay() != "none"  && !NewGame(true))
2477
	{
2461
	{
2478
		gui.ActivatePage("ReplayStartError", 0.25, error_output);
2462
		gui.ActivatePage("ReplayStartError", 0.25, error_output);
2479
	}
2463
	}
Lines 2855-2860 Link Here
2855
	EditControl();
2839
	EditControl();
2856
}
2840
}
2857
2841
2842
void GAME::BindActionsToGUI()
2843
{
2844
	set_car_name.connect(gui.GetOption("game.car").signal_val);
2845
	set_car_paint.connect(gui.GetOption("game.car_paint").signal_val);
2846
	set_car_color_hue.connect(gui.GetOption("game.car_color_hue").signal_val);
2847
	set_car_color_sat.connect(gui.GetOption("game.car_color_sat").signal_val);
2848
	set_car_color_val.connect(gui.GetOption("game.car_color_val").signal_val);
2849
	set_car_ai_type.connect(gui.GetOption("game.ai_type").signal_val);
2850
	set_car_ai_level.connect(gui.GetOption("game.ai_level").signal_val);
2851
	set_cars_num.connect(gui.GetOption("game.cars_num").signal_val);
2852
	set_track_image.connect(gui.GetOption("game.track").signal_val);
2853
	set_control.connect(gui.GetOption("controledit.string").signal_val);
2854
}
2858
2855
2859
void GAME::RegisterActions()
2856
void GAME::RegisterActions()
2860
{
2857
{
(-)src/game.h (+1 lines)
Lines 201-206 Link Here
201
	void SetTrackImage(const std::string & value);
201
	void SetTrackImage(const std::string & value);
202
	void SetControl(const std::string & value);
202
	void SetControl(const std::string & value);
203
203
204
	void BindActionsToGUI();
204
	void RegisterActions();
205
	void RegisterActions();
205
	void InitActionMap(std::map<std::string, Slot0*> & actionmap);
206
	void InitActionMap(std::map<std::string, Slot0*> & actionmap);
206
207
(-)src/sound.cpp (-73 / +75 lines)
Lines 30-46 Link Here
30
}
30
}
31
31
32
SOUND::SOUND() :
32
SOUND::SOUND() :
33
	log_error(0),
33
	deviceinfo(0, 0, 0, 0),
34
	deviceinfo(0, 0, 0, 0),
35
	sound_volume(0),
34
	initdone(false),
36
	initdone(false),
35
	disable(false),
37
	disable(false),
36
	paused(true),
37
	sampler_lock(0),
38
	sampler_lock(0),
38
	source_lock(0),
39
	source_lock(0),
40
	set_pause(true),
39
	max_active_sources(64),
41
	max_active_sources(64),
40
	sources_num(0),
42
	sources_num(0),
41
	samplers_num(0)
43
	sources_pause(true),
44
	samplers_num(0),
45
	samplers_pause(true)
42
{
46
{
43
	volume_filter.SetFilterOrder0(1.0);
44
	sources.reserve(64);
47
	sources.reserve(64);
45
	samplers.reserve(64);
48
	samplers.reserve(64);
46
}
49
}
Lines 115-125 Link Here
115
	}
118
	}
116
119
117
	deviceinfo = SOUNDINFO(samples, frequency, channels, bytespersample);
120
	deviceinfo = SOUNDINFO(samples, frequency, channels, bytespersample);
118
121
	log_error = &error_output;
119
	initdone = true;
122
	initdone = true;
120
121
	SetVolume(1.0);
123
	SetVolume(1.0);
122
124
125
	// enable sound, run callback
126
	SDL_PauseAudio(false);
127
123
	return true;
128
	return true;
124
}
129
}
125
130
Lines 138-183 Link Here
138
	disable = true;
143
	disable = true;
139
}
144
}
140
145
141
void SOUND::Pause(bool value)
146
void SOUND::Update(bool pause)
142
{
143
	if (paused != value)
144
	{
145
		SDL_PauseAudio(value);
146
		paused = value;
147
	}
148
}
149
150
void SOUND::Update()
151
{
147
{
152
	if (disable) return;
148
	if (disable) return;
153
149
150
	set_pause = pause;
151
154
	GetSourceChanges();
152
	GetSourceChanges();
155
153
156
	ProcessSourceStop();
154
	ProcessSourceStop();
157
155
158
	ProcessSourceRemove();
159
160
	ProcessSources();
156
	ProcessSources();
161
157
162
	SetSamplerChanges();
158
	ProcessSourceRemove();
163
164
	// short circuit if paused(sound thread blocked)
165
	if (paused)
166
	{
167
		GetSamplerChanges();
168
169
		ProcessSamplerAdd();
170
171
		ProcessSamplerRemove();
172
173
		SetSourceChanges();
174
175
		GetSourceChanges();
176
177
		ProcessSourceStop();
178
159
179
		ProcessSourceRemove();
160
	SetSamplerChanges();
180
	}
181
}
161
}
182
162
183
void SOUND::SetMaxActiveSources(size_t value)
163
void SOUND::SetMaxActiveSources(size_t value)
Lines 192-209 Link Here
192
	size_t id = item_num;
172
	size_t id = item_num;
193
	if (id < items.size())
173
	if (id < items.size())
194
	{
174
	{
175
		// reuse free slot
195
		size_t idn = items[id].id;
176
		size_t idn = items[id].id;
196
		if (idn != id)
177
		if (idn != id)
197
		{
178
		{
198
			// swap back redirected item
179
			// free slot is redirecting to other item
199
			assert(idn < id);
180
			assert(idn < id);
181
182
			// swap redirected item back
200
			items[id] = items[idn];
183
			items[id] = items[idn];
184
185
			// use now free slot
201
			id = idn;
186
			id = idn;
202
		}
187
		}
203
		items[id] = item;
188
		items[id] = item;
204
	}
189
	}
205
	else
190
	else
206
	{
191
	{
192
		// add item to new slot
207
		items.push_back(item);
193
		items.push_back(item);
208
	}
194
	}
209
	items[id].id = id;
195
	items[id].id = id;
Lines 217-225 Link Here
217
inline void RemoveItem(size_t id, std::vector<T> & items, size_t & item_num)
203
inline void RemoveItem(size_t id, std::vector<T> & items, size_t & item_num)
218
{
204
{
219
	assert(id < items.size());
205
	assert(id < items.size());
206
207
	// get item true id
220
	size_t idn = items[id].id;
208
	size_t idn = items[id].id;
221
	assert(idn < item_num);
209
	assert(idn < item_num);
210
211
	// pop last item
222
	--item_num;
212
	--item_num;
213
223
	// swap last item with current
214
	// swap last item with current
224
	size_t idl = items[item_num].id;
215
	size_t idl = items[item_num].id;
225
	if (idl != item_num)
216
	if (idl != item_num)
Lines 270-283 Link Here
270
	ns.id = -1;
261
	ns.id = -1;
271
	sampler_add.getFirst().push_back(ns);
262
	sampler_add.getFirst().push_back(ns);
272
263
273
	//std::cout << "Add sound source: " << id << " " << buffer->GetName() << std::endl;
264
	//*log_error << "Add sound source: " << id << " " << buffer->GetName() << std::endl;
274
	return id;
265
	return id;
275
}
266
}
276
267
277
void SOUND::RemoveSource(size_t id)
268
void SOUND::RemoveSource(size_t id)
278
{
269
{
279
	// notify sound thread, it will notify main thread to remove the source
270
	// notify sound and main thread to remove the source/sampler
280
	//std::cout << "To be removed source: " << id << " " << sources[sources[id].id].buffer->GetName() << std::endl;
281
	sampler_remove.getFirst().push_back(id);
271
	sampler_remove.getFirst().push_back(id);
282
}
272
}
283
273
Lines 343-356 Link Here
343
333
344
void SOUND::SetVolume(float value)
334
void SOUND::SetVolume(float value)
345
{
335
{
346
	volume_filter.SetFilterOrder0(clamp(value, 0.f, 1.f));
336
	sound_volume = value;
347
}
337
}
348
338
349
void SOUND::GetSourceChanges()
339
void SOUND::GetSourceChanges()
350
{
340
{
351
	Lock(source_lock);
341
	Lock(source_lock);
352
	source_stop.swapFirst();
342
	source_stop.swapFirst();
353
	source_remove.swapFirst();
354
	Unlock(source_lock);
343
	Unlock(source_lock);
355
}
344
}
356
345
Lines 368-384 Link Here
368
357
369
void SOUND::ProcessSourceRemove()
358
void SOUND::ProcessSourceRemove()
370
{
359
{
371
	std::vector<size_t> & sremove = source_remove.getFirst();
360
	std::vector<size_t> & sremove = sampler_remove.getFirst();
372
	for (size_t i = 0; i < sremove.size(); ++i)
361
	for (size_t i = 0; i < sremove.size(); ++i)
373
	{
362
	{
374
		size_t id = sremove[i];
363
		size_t id = sremove[i];
375
		assert(id < sources.size());
364
		assert(id < sources.size());
365
376
		size_t idn = sources[id].id;
366
		size_t idn = sources[id].id;
377
		assert(idn < sources_num);
367
		assert(idn < sources_num);
378
		//std::cout << "Remove sound source: " << id << " " << sources[idn].buffer->GetName() << std::endl;
368
		//*log_error << "Remove sound source: " << id << " " << sources[idn].buffer->GetName() << std::endl;
369
379
		RemoveItem(id, sources, sources_num);
370
		RemoveItem(id, sources, sources_num);
380
	}
371
	}
381
	sremove.clear();
382
}
372
}
383
373
384
void SOUND::ProcessSources()
374
void SOUND::ProcessSources()
Lines 436-443 Link Here
436
			}
426
			}
437
		}
427
		}
438
428
439
		supdate[i].gain1 = gain1 * Sampler::denom;
429
		// fade sound volume
440
		supdate[i].gain2 = gain2 * Sampler::denom;
430
		float volume = set_pause ? 0 : sound_volume;
431
432
		supdate[i].gain1 = volume * gain1 * Sampler::denom;
433
		supdate[i].gain2 = volume * gain2 * Sampler::denom;
441
		supdate[i].pitch = src.pitch * Sampler::denom;
434
		supdate[i].pitch = src.pitch * Sampler::denom;
442
	}
435
	}
443
436
Lines 471-476 Link Here
471
	if (sampler_update.getFirst().size()) sampler_update.swapFirst();
464
	if (sampler_update.getFirst().size()) sampler_update.swapFirst();
472
	if (sampler_add.getFirst().size()) sampler_add.swapFirst();
465
	if (sampler_add.getFirst().size()) sampler_add.swapFirst();
473
	if (sampler_remove.getFirst().size()) sampler_remove.swapFirst();
466
	if (sampler_remove.getFirst().size()) sampler_remove.swapFirst();
467
	sources_pause = set_pause;
474
	Unlock(sampler_lock);
468
	Unlock(sampler_lock);
475
}
469
}
476
470
Lines 478-510 Link Here
478
{
472
{
479
	Lock(sampler_lock);
473
	Lock(sampler_lock);
480
	sampler_update.swapLast();
474
	sampler_update.swapLast();
481
	sampler_remove.swapLast();
482
	sampler_add.swapLast();
475
	sampler_add.swapLast();
476
	sampler_remove.swapLast();
477
	samplers_fade = samplers_pause != sources_pause;
478
	samplers_pause = sources_pause;
483
	Unlock(sampler_lock);
479
	Unlock(sampler_lock);
484
}
480
}
485
481
486
void SOUND::ProcessSamplerUpdate()
482
void SOUND::ProcessSamplerUpdate()
487
{
483
{
488
	std::vector<SamplerUpdate> & supdate = sampler_update.getLast();
484
	std::vector<SamplerUpdate> & supdate = sampler_update.getLast();
489
	if (samplers_num == supdate.size())
485
	if (supdate.empty()) return;
486
	
487
	assert(samplers_num == supdate.size());
488
	for (size_t i = 0; i < samplers_num; ++i)
490
	{
489
	{
491
		for (size_t i = 0; i < samplers_num; ++i)
490
		samplers[i].gain1 = supdate[i].gain1;
492
		{
491
		samplers[i].gain2 = supdate[i].gain2;
493
			samplers[i].gain1 = supdate[i].gain1;
492
		samplers[i].pitch = supdate[i].pitch;
494
			samplers[i].gain2 = supdate[i].gain2;
495
			samplers[i].pitch = supdate[i].pitch;
496
		}
497
	}
493
	}
498
	supdate.clear();
494
	supdate.clear();
499
}
495
}
500
496
501
void SOUND::ProcessSamplers(unsigned char *stream, int len)
497
void SOUND::ProcessSamplers(unsigned char *stream, int len)
502
{
498
{
503
	// set buffers and clear stream
499
	// clear stream
500
	memset(stream, 0, len);
501
502
	// pause sampling
503
	if (samplers_pause && !samplers_fade)
504
		return;
505
506
	// init sampling buffers
504
	int len4 = len / 4;
507
	int len4 = len / 4;
505
	buffer1.resize(len4);
508
	buffer1.resize(len4);
506
	buffer2.resize(len4);
509
	buffer2.resize(len4);
507
	memset(stream, 0, len);
508
510
509
	// run samplers
511
	// run samplers
510
	short * sstream = (short*)stream;
512
	short * sstream = (short*)stream;
Lines 519-531 Link Here
519
		{
521
		{
520
			SampleAndAdvanceWithPitch16bit(smp, &buffer1[0], &buffer2[0], len4);
522
			SampleAndAdvanceWithPitch16bit(smp, &buffer1[0], &buffer2[0], len4);
521
523
522
			volume_filter.Filter(&buffer1[0], &buffer2[0], len4);
523
524
			for (int n = 0; n < len4; ++n)
524
			for (int n = 0; n < len4; ++n)
525
			{
525
			{
526
				int pos = n * 2;
526
				int pos = n * 2;
527
				sstream[pos] = clamp(sstream[pos] + buffer1[n], -32768, 32767);
527
				int val1 = sstream[pos] + buffer1[n];
528
				sstream[pos + 1] = clamp(sstream[pos + 1] + buffer2[n], -32768, 32767);
528
				int val2 = sstream[pos + 1] + buffer2[n];
529
530
				val1 = clamp(val1, -32768, 32767);
531
				val2 = clamp(val2, -32768, 32767);
532
533
				sstream[pos] = val1;
534
				sstream[pos + 1] = val2;
529
			}
535
			}
530
		}
536
		}
531
		else
537
		else
Lines 541-557 Link Here
541
void SOUND::ProcessSamplerRemove()
547
void SOUND::ProcessSamplerRemove()
542
{
548
{
543
	std::vector<size_t> & sremove = sampler_remove.getLast();
549
	std::vector<size_t> & sremove = sampler_remove.getLast();
544
	if (!sremove.empty())
550
	for (size_t i = 0; i < sremove.size(); ++i)
545
	{
551
	{
546
		for (size_t i = 0; i < sremove.size(); ++i)
552
		size_t id = sremove[i];
547
		{
553
		assert(id < samplers.size());
548
			size_t id = sremove[i];
554
		RemoveItem(id, samplers, samplers_num);
549
			assert(id < samplers.size());
550
			RemoveItem(id, samplers, samplers_num);
551
		}
552
		source_remove.getLast() = sremove;
553
		sremove.clear();
554
	}
555
	}
556
	sremove.clear();
555
}
557
}
556
558
557
void SOUND::ProcessSamplerAdd()
559
void SOUND::ProcessSamplerAdd()
Lines 589-595 Link Here
589
{
591
{
590
	Lock(source_lock);
592
	Lock(source_lock);
591
	if (source_stop.getLast().size()) source_stop.swapLast();
593
	if (source_stop.getLast().size()) source_stop.swapLast();
592
	if (source_remove.getLast().size()) source_remove.swapLast();
593
	Unlock(source_lock);
594
	Unlock(source_lock);
594
}
595
}
595
596
Lines 600-611 Link Here
600
601
601
	GetSamplerChanges();
602
	GetSamplerChanges();
602
603
604
	ProcessSamplerAdd();
605
603
	ProcessSamplerUpdate();
606
	ProcessSamplerUpdate();
604
607
605
	ProcessSamplers(stream, len);
608
	ProcessSamplers(stream, len);
606
609
607
	ProcessSamplerAdd();
608
609
	ProcessSamplerRemove();
610
	ProcessSamplerRemove();
610
611
611
	SetSourceChanges();
612
	SetSourceChanges();
Lines 622-630 Link Here
622
	assert(len > 0);
623
	assert(len > 0);
623
	assert(sampler.buffer);
624
	assert(sampler.buffer);
624
625
625
	// if not playing, fill output buffers with silence, should not happen
626
	// if not playing, fill output buffers with silence
626
	if (!sampler.playing)
627
	if (!sampler.playing)
627
	{
628
	{
629
		// should be dealt with before getting here
628
		assert(0);
630
		assert(0);
629
		for (int i = 0; i < len; ++i)
631
		for (int i = 0; i < len; ++i)
630
		{
632
		{
(-)src/sound.h (-9 / +9 lines)
Lines 33-43 Link Here
33
	// disable sound
33
	// disable sound
34
	void Disable();
34
	void Disable();
35
35
36
	// pause sound
37
	void Pause(bool value);
38
39
	// commit state changes
36
	// commit state changes
40
	void Update();
37
	void Update(bool pause);
41
38
42
	// active sources limit can be adjusted at runtime
39
	// active sources limit can be adjusted at runtime
43
	void SetMaxActiveSources(size_t value);
40
	void SetMaxActiveSources(size_t value);
Lines 69-82 Link Here
69
	void SetVolume(float value);
66
	void SetVolume(float value);
70
67
71
private:
68
private:
69
	std::ostream * log_error;
72
	SOUNDINFO deviceinfo;
70
	SOUNDINFO deviceinfo;
73
	SOUNDFILTER volume_filter;
74
	MATHVECTOR<float, 3> listener_pos;
71
	MATHVECTOR<float, 3> listener_pos;
75
	MATHVECTOR<float, 3> listener_vel;
72
	MATHVECTOR<float, 3> listener_vel;
76
	QUATERNION<float> listener_rot;
73
	QUATERNION<float> listener_rot;
74
	float sound_volume;
77
	bool initdone;
75
	bool initdone;
78
	bool disable;
76
	bool disable;
79
	bool paused;
80
77
81
	// state structs
78
	// state structs
82
	struct Source
79
	struct Source
Lines 95-102 Link Here
95
92
96
	struct Sampler
93
	struct Sampler
97
	{
94
	{
98
		static const int denom = 1 << 15;
95
		static const int denom = 32768;
99
		static const int max_gain_delta = (denom * 100) / 44100;
96
		static const int max_gain_delta = (denom * 173) / 44100; // 256 samples from min to max gain
100
		const SOUNDBUFFER * buffer;
97
		const SOUNDBUFFER * buffer;
101
		int samples_per_channel;
98
		int samples_per_channel;
102
		int sample_pos;
99
		int sample_pos;
Lines 135-155 Link Here
135
	TrippleBuffer<SamplerUpdate> sampler_update;
132
	TrippleBuffer<SamplerUpdate> sampler_update;
136
	TrippleBuffer<SamplerAdd> sampler_add;
133
	TrippleBuffer<SamplerAdd> sampler_add;
137
	TrippleBuffer<size_t> sampler_remove;
134
	TrippleBuffer<size_t> sampler_remove;
138
	TrippleBuffer<size_t> source_remove;
139
	TrippleBuffer<size_t> source_stop;
135
	TrippleBuffer<size_t> source_stop;
140
	SDL_mutex * sampler_lock;
136
	SDL_mutex * sampler_lock;
141
	SDL_mutex * source_lock;
137
	SDL_mutex * source_lock;
138
	bool set_pause;
142
139
143
	// sound sources state
140
	// sound sources state
144
	std::vector<SourceActive> sources_active;
141
	std::vector<SourceActive> sources_active;
145
	std::vector<Source> sources;
142
	std::vector<Source> sources;
146
	size_t max_active_sources;
143
	size_t max_active_sources;
147
	size_t sources_num;
144
	size_t sources_num;
145
	bool sources_pause;
148
146
149
	// sound thread state
147
	// sound thread state
150
	std::vector<int> buffer1, buffer2;
148
	std::vector<int> buffer1, buffer2;
151
	std::vector<Sampler> samplers;
149
	std::vector<Sampler> samplers;
152
	size_t samplers_num;
150
	size_t samplers_num;
151
	bool samplers_pause;
152
	bool samplers_fade;
153
153
154
	// main thread methods
154
	// main thread methods
155
	void GetSourceChanges();
155
	void GetSourceChanges();
(-)src/texture.cpp (+3 lines)
Lines 179-184 Link Here
179
	else
179
	else
180
	{
180
	{
181
		error << "Error loading texture file: " + path << std::endl;
181
		error << "Error loading texture file: " + path << std::endl;
182
		error << IMG_GetError();
182
		return false;
183
		return false;
183
	}
184
	}
184
185
Lines 303-308 Link Here
303
		else
304
		else
304
		{
305
		{
305
			error << "Error loading texture file: " + path + " (" + cubefiles[i] + ")" << std::endl;
306
			error << "Error loading texture file: " + path + " (" + cubefiles[i] + ")" << std::endl;
307
			error << IMG_GetError();
306
			return false;
308
			return false;
307
		}
309
		}
308
310
Lines 477-482 Link Here
477
		if (!orig_surface)
479
		if (!orig_surface)
478
		{
480
		{
479
			error << "Error loading texture file: " << path << std::endl;
481
			error << "Error loading texture file: " << path << std::endl;
482
			error << IMG_GetError();
480
			return false;
483
			return false;
481
		}
484
		}
482
	}
485
	}

Return to bug 434148