Skip to content

Commit eb2c19b

Browse files
committedJan 8, 2017
Move ClientEnvironment to dedicated cpp/header files
1 parent b074683 commit eb2c19b

8 files changed

+1042
-1003
lines changed
 

Diff for: ‎src/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -508,6 +508,7 @@ set(client_SRCS
508508
${client_irrlicht_changes_SRCS}
509509
camera.cpp
510510
client.cpp
511+
clientenvironment.cpp
511512
clientmap.cpp
512513
clientmedia.cpp
513514
clientobject.cpp

Diff for: ‎src/client.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
2121
#define CLIENT_HEADER
2222

2323
#include "network/connection.h"
24-
#include "environment.h"
24+
#include "clientenvironment.h"
2525
#include "irrlichttypes_extrabloated.h"
2626
#include "threading/mutex.h"
2727
#include <ostream>

Diff for: ‎src/clientenvironment.cpp

+847
Large diffs are not rendered by default.

Diff for: ‎src/clientenvironment.h

+191
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,191 @@
1+
/*
2+
Minetest
3+
Copyright (C) 2010-2017 celeron55, Perttu Ahola <celeron55@gmail.com>
4+
5+
This program is free software; you can redistribute it and/or modify
6+
it under the terms of the GNU Lesser General Public License as published by
7+
the Free Software Foundation; either version 2.1 of the License, or
8+
(at your option) any later version.
9+
10+
This program is distributed in the hope that it will be useful,
11+
but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
GNU Lesser General Public License for more details.
14+
15+
You should have received a copy of the GNU Lesser General Public License along
16+
with this program; if not, write to the Free Software Foundation, Inc.,
17+
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18+
*/
19+
20+
#ifndef CLIENT_ENVIRONMENT_HEADER
21+
#define CLIENT_ENVIRONMENT_HEADER
22+
23+
#include <IrrlichtDevice.h>
24+
#include <ISceneManager.h>
25+
#include "environment.h"
26+
#include "clientobject.h"
27+
28+
class ClientSimpleObject;
29+
class ClientMap;
30+
class ClientActiveObject;
31+
class GenericCAO;
32+
class LocalPlayer;
33+
34+
/*
35+
The client-side environment.
36+
37+
This is not thread-safe.
38+
Must be called from main (irrlicht) thread (uses the SceneManager)
39+
Client uses an environment mutex.
40+
*/
41+
42+
enum ClientEnvEventType
43+
{
44+
CEE_NONE,
45+
CEE_PLAYER_DAMAGE,
46+
CEE_PLAYER_BREATH
47+
};
48+
49+
struct ClientEnvEvent
50+
{
51+
ClientEnvEventType type;
52+
union {
53+
//struct{
54+
//} none;
55+
struct{
56+
u8 amount;
57+
bool send_to_server;
58+
} player_damage;
59+
struct{
60+
u16 amount;
61+
} player_breath;
62+
};
63+
};
64+
65+
class ClientEnvironment : public Environment
66+
{
67+
public:
68+
ClientEnvironment(ClientMap *map, scene::ISceneManager *smgr,
69+
ITextureSource *texturesource, IGameDef *gamedef,
70+
IrrlichtDevice *device);
71+
~ClientEnvironment();
72+
73+
Map & getMap();
74+
ClientMap & getClientMap();
75+
76+
IGameDef *getGameDef()
77+
{ return m_gamedef; }
78+
79+
void step(f32 dtime);
80+
81+
virtual void setLocalPlayer(LocalPlayer *player);
82+
LocalPlayer *getLocalPlayer() { return m_local_player; }
83+
84+
/*
85+
ClientSimpleObjects
86+
*/
87+
88+
void addSimpleObject(ClientSimpleObject *simple);
89+
90+
/*
91+
ActiveObjects
92+
*/
93+
94+
GenericCAO* getGenericCAO(u16 id);
95+
ClientActiveObject* getActiveObject(u16 id);
96+
97+
/*
98+
Adds an active object to the environment.
99+
Environment handles deletion of object.
100+
Object may be deleted by environment immediately.
101+
If id of object is 0, assigns a free id to it.
102+
Returns the id of the object.
103+
Returns 0 if not added and thus deleted.
104+
*/
105+
u16 addActiveObject(ClientActiveObject *object);
106+
107+
void addActiveObject(u16 id, u8 type, const std::string &init_data);
108+
void removeActiveObject(u16 id);
109+
110+
void processActiveObjectMessage(u16 id, const std::string &data);
111+
112+
/*
113+
Callbacks for activeobjects
114+
*/
115+
116+
void damageLocalPlayer(u8 damage, bool handle_hp=true);
117+
void updateLocalPlayerBreath(u16 breath);
118+
119+
/*
120+
Client likes to call these
121+
*/
122+
123+
// Get all nearby objects
124+
void getActiveObjects(v3f origin, f32 max_d,
125+
std::vector<DistanceSortedActiveObject> &dest);
126+
127+
// Get event from queue. CEE_NONE is returned if queue is empty.
128+
ClientEnvEvent getClientEvent();
129+
130+
/*!
131+
* Gets closest object pointed by the shootline.
132+
* Returns NULL if not found.
133+
*
134+
* \param[in] shootline_on_map the shootline for
135+
* the test in world coordinates
136+
* \param[out] intersection_point the first point where
137+
* the shootline meets the object. Valid only if
138+
* not NULL is returned.
139+
* \param[out] intersection_normal the normal vector of
140+
* the intersection, pointing outwards. Zero vector if
141+
* the shootline starts in an active object.
142+
* Valid only if not NULL is returned.
143+
*/
144+
ClientActiveObject * getSelectedActiveObject(
145+
const core::line3d<f32> &shootline_on_map,
146+
v3f *intersection_point,
147+
v3s16 *intersection_normal
148+
);
149+
150+
/*!
151+
* Performs a raycast on the world.
152+
* Returns the first thing the shootline meets.
153+
*
154+
* @param[in] shootline the shootline, starting from
155+
* the camera position. This also gives the maximal distance
156+
* of the search.
157+
* @param[in] liquids_pointable if false, liquids are ignored
158+
* @param[in] look_for_object if false, objects are ignored
159+
*/
160+
PointedThing getPointedThing(
161+
core::line3d<f32> shootline,
162+
bool liquids_pointable,
163+
bool look_for_object);
164+
165+
u16 attachement_parent_ids[USHRT_MAX + 1];
166+
167+
const std::list<std::string> &getPlayerNames() { return m_player_names; }
168+
void addPlayerName(const std::string &name) { m_player_names.push_back(name); }
169+
void removePlayerName(const std::string &name) { m_player_names.remove(name); }
170+
void updateCameraOffset(v3s16 camera_offset)
171+
{ m_camera_offset = camera_offset; }
172+
v3s16 getCameraOffset() const { return m_camera_offset; }
173+
private:
174+
ClientMap *m_map;
175+
LocalPlayer *m_local_player;
176+
scene::ISceneManager *m_smgr;
177+
ITextureSource *m_texturesource;
178+
IGameDef *m_gamedef;
179+
IrrlichtDevice *m_irr;
180+
UNORDERED_MAP<u16, ClientActiveObject*> m_active_objects;
181+
std::vector<ClientSimpleObject*> m_simple_objects;
182+
std::queue<ClientEnvEvent> m_client_event_queue;
183+
IntervalLimiter m_active_object_light_update_interval;
184+
IntervalLimiter m_lava_hurt_interval;
185+
IntervalLimiter m_drowning_interval;
186+
IntervalLimiter m_breathing_interval;
187+
std::list<std::string> m_player_names;
188+
v3s16 m_camera_offset;
189+
};
190+
191+
#endif

Diff for: ‎src/collision.cpp

+1-5
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,8 @@ with this program; if not, write to the Free Software Foundation, Inc.,
2222
#include "map.h"
2323
#include "nodedef.h"
2424
#include "gamedef.h"
25-
#include "log.h"
26-
#include "environment.h"
25+
#include "clientenvironment.h"
2726
#include "serverobject.h"
28-
#include <vector>
29-
#include <set>
30-
#include "util/timetaker.h"
3127
#include "profiler.h"
3228

3329
// float error is 10 - 9.96875 = 0.03125

Diff for: ‎src/content_cso.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,8 @@ with this program; if not, write to the Free Software Foundation, Inc.,
2020
#include "content_cso.h"
2121
#include <IBillboardSceneNode.h>
2222
#include "client/tile.h"
23-
#include "environment.h"
23+
#include "clientenvironment.h"
2424
#include "gamedef.h"
25-
#include "log.h"
2625
#include "map.h"
2726

2827
/*

Diff for: ‎src/environment.cpp

-828
Large diffs are not rendered by default.

Diff for: ‎src/environment.h

-167
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ class ITextureSource;
5050
class IGameDef;
5151
class Map;
5252
class ServerMap;
53-
class ClientMap;
5453
class GameScripting;
5554
class Player;
5655
class RemotePlayer;
@@ -525,171 +524,5 @@ class ServerEnvironment : public Environment
525524
UNORDERED_MAP<u32, u16> m_particle_spawner_attachments;
526525
};
527526

528-
#ifndef SERVER
529-
530-
#include "clientobject.h"
531-
#include "content_cao.h"
532-
533-
class ClientSimpleObject;
534-
535-
/*
536-
The client-side environment.
537-
538-
This is not thread-safe.
539-
Must be called from main (irrlicht) thread (uses the SceneManager)
540-
Client uses an environment mutex.
541-
*/
542-
543-
enum ClientEnvEventType
544-
{
545-
CEE_NONE,
546-
CEE_PLAYER_DAMAGE,
547-
CEE_PLAYER_BREATH
548-
};
549-
550-
struct ClientEnvEvent
551-
{
552-
ClientEnvEventType type;
553-
union {
554-
//struct{
555-
//} none;
556-
struct{
557-
u8 amount;
558-
bool send_to_server;
559-
} player_damage;
560-
struct{
561-
u16 amount;
562-
} player_breath;
563-
};
564-
};
565-
566-
class ClientEnvironment : public Environment
567-
{
568-
public:
569-
ClientEnvironment(ClientMap *map, scene::ISceneManager *smgr,
570-
ITextureSource *texturesource, IGameDef *gamedef,
571-
IrrlichtDevice *device);
572-
~ClientEnvironment();
573-
574-
Map & getMap();
575-
ClientMap & getClientMap();
576-
577-
IGameDef *getGameDef()
578-
{ return m_gamedef; }
579-
580-
void step(f32 dtime);
581-
582-
virtual void setLocalPlayer(LocalPlayer *player);
583-
LocalPlayer *getLocalPlayer() { return m_local_player; }
584-
585-
/*
586-
ClientSimpleObjects
587-
*/
588-
589-
void addSimpleObject(ClientSimpleObject *simple);
590-
591-
/*
592-
ActiveObjects
593-
*/
594-
595-
GenericCAO* getGenericCAO(u16 id);
596-
ClientActiveObject* getActiveObject(u16 id);
597-
598-
/*
599-
Adds an active object to the environment.
600-
Environment handles deletion of object.
601-
Object may be deleted by environment immediately.
602-
If id of object is 0, assigns a free id to it.
603-
Returns the id of the object.
604-
Returns 0 if not added and thus deleted.
605-
*/
606-
u16 addActiveObject(ClientActiveObject *object);
607-
608-
void addActiveObject(u16 id, u8 type, const std::string &init_data);
609-
void removeActiveObject(u16 id);
610-
611-
void processActiveObjectMessage(u16 id, const std::string &data);
612-
613-
/*
614-
Callbacks for activeobjects
615-
*/
616-
617-
void damageLocalPlayer(u8 damage, bool handle_hp=true);
618-
void updateLocalPlayerBreath(u16 breath);
619-
620-
/*
621-
Client likes to call these
622-
*/
623-
624-
// Get all nearby objects
625-
void getActiveObjects(v3f origin, f32 max_d,
626-
std::vector<DistanceSortedActiveObject> &dest);
627-
628-
// Get event from queue. CEE_NONE is returned if queue is empty.
629-
ClientEnvEvent getClientEvent();
630-
631-
/*!
632-
* Gets closest object pointed by the shootline.
633-
* Returns NULL if not found.
634-
*
635-
* \param[in] shootline_on_map the shootline for
636-
* the test in world coordinates
637-
* \param[out] intersection_point the first point where
638-
* the shootline meets the object. Valid only if
639-
* not NULL is returned.
640-
* \param[out] intersection_normal the normal vector of
641-
* the intersection, pointing outwards. Zero vector if
642-
* the shootline starts in an active object.
643-
* Valid only if not NULL is returned.
644-
*/
645-
ClientActiveObject * getSelectedActiveObject(
646-
const core::line3d<f32> &shootline_on_map,
647-
v3f *intersection_point,
648-
v3s16 *intersection_normal
649-
);
650-
651-
/*!
652-
* Performs a raycast on the world.
653-
* Returns the first thing the shootline meets.
654-
*
655-
* @param[in] shootline the shootline, starting from
656-
* the camera position. This also gives the maximal distance
657-
* of the search.
658-
* @param[in] liquids_pointable if false, liquids are ignored
659-
* @param[in] look_for_object if false, objects are ignored
660-
*/
661-
PointedThing getPointedThing(
662-
core::line3d<f32> shootline,
663-
bool liquids_pointable,
664-
bool look_for_object);
665-
666-
u16 attachement_parent_ids[USHRT_MAX + 1];
667-
668-
const std::list<std::string> &getPlayerNames() { return m_player_names; }
669-
void addPlayerName(const std::string &name) { m_player_names.push_back(name); }
670-
void removePlayerName(const std::string &name) { m_player_names.remove(name); }
671-
void updateCameraOffset(v3s16 camera_offset)
672-
{ m_camera_offset = camera_offset; }
673-
v3s16 getCameraOffset() const { return m_camera_offset; }
674-
private:
675-
ClientMap *m_map;
676-
LocalPlayer *m_local_player;
677-
scene::ISceneManager *m_smgr;
678-
ITextureSource *m_texturesource;
679-
IGameDef *m_gamedef;
680-
IrrlichtDevice *m_irr;
681-
UNORDERED_MAP<u16, ClientActiveObject*> m_active_objects;
682-
std::vector<ClientSimpleObject*> m_simple_objects;
683-
std::queue<ClientEnvEvent> m_client_event_queue;
684-
IntervalLimiter m_active_object_light_update_interval;
685-
IntervalLimiter m_lava_hurt_interval;
686-
IntervalLimiter m_drowning_interval;
687-
IntervalLimiter m_breathing_interval;
688-
std::list<std::string> m_player_names;
689-
v3s16 m_camera_offset;
690-
};
691-
692-
#endif
693-
694527
#endif
695528

0 commit comments

Comments
 (0)
Please sign in to comment.