Imported more code from the old engine.
[peakengine.git] / engine / include / core / GameEngine.h
blobd9a97e547a7d042f45d8572836c54d73cec49b43
1 /*
2 Copyright (C) 2008 Mathias Gottschlag
4 Permission is hereby granted, free of charge, to any person obtaining a copy of
5 this software and associated documentation files (the "Software"), to deal in the
6 Software without restriction, including without limitation the rights to use,
7 copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
8 Software, and to permit persons to whom the Software is furnished to do so,
9 subject to the following conditions:
11 The above copyright notice and this permission notice shall be included in all
12 copies or substantial portions of the Software.
14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
15 INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
16 PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
17 HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
18 OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
19 SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 #ifndef _GAMEENGINE_H_
23 #define _GAMEENGINE_H_
25 //#include "core/Config.h"
27 #include <string>
29 #if defined(_MSC_VER) || defined(_WINDOWS_) || defined(_WIN32)
30 #include <time.h>
31 #include <winsock2.h>
32 #include <winbase.h>
33 #define usleep(x) Sleep(x/1000)
35 #else
36 #include <sys/time.h>
37 #endif
38 #if defined(_MSC_VER) || defined(_WINDOWS_) || defined(_WIN32)
39 int gettimeofday(struct timeval* tv, void *timezone);
40 #endif
42 namespace peak {
43 /**
44 * \mainpage PeakEngine
46 * \section about About
48 * The PeakEngine is a multiplatform, scriptable, easy-to use game engine with
49 * shader-based graphics, automatic networking, 3D sound and networked physics.
50 * The engine is completely controlled in Lua and XML. It is based on Horde3D,
51 * FreeImagePlus, guichan, Bullet, enet, tolua++, Lua, glfw, OpenAL, freealut,
52 * libogg and libvorbis.
54 * \section design Design
55 * \subsection overview Overview
56 * The engine is controlled completely through Lua and XML, with the possibility
57 * of binary plugins being planned in the near future. The game logic itself is
58 * splitted up into two parts: The level (which mostly holds static objects),
59 * and entities which are all dynamic objects.
60 * \subsection entity Entity
61 * Entities can contain physics, 2D and 3D graphics and are defined in a XML file
62 * like this (very simple example which just creates a cube with physics):
63 * \code
64 * <?xml version="1.0" standalone="yes"?>
65 * <entity>
66 * <name>Test</name>
67 * <property name="position" type="alias" value="testbody.position" />
69 * <body name="testbody">
70 * <shape name="testshape" type="box" size="1/1/1" />
71 * <scenenode name="testnode" type="mesh" file="cube.scene.xml" scale="1/1/1" />
72 * </body>
74 * <link type="direct" source="testbody.rotation.y" target="global.compass" />
75 * </entity>
76 * \endcode
77 * This creates a cube which has a physics body ("testbody"), a collision shape
78 * ("testshape") and a scene node ("testnode").
80 * Additionally Entities and all other objects derived from GameObject can have
81 * properties which can be used via their name. In this case only "position" is
82 * defined, liked to the position of the body, but it is possible to define
83 * other properties. Example for a simple integer property:
84 * \code
85 * <property name="hitpoints" type="integer" value="100" />
86 * \endcode
87 * The properties which belong to entities are synchronized automatically via
88 * the network, this does not apply to other game objects, like SceneNode.
90 * Additionally one can create links between properties so that one property
91 * automatically gets changed whenever another changes. Links can also be created
92 * between a Property and a script function ("Call script whenever property "x"
93 * changes") or an Event and a script function ("Call script whenever
94 * input.KeyDown is triggered").
96 * The following is an example for the latter:
97 * \code
98 * <link name="zlink" type="script" source="input.KeyPressed" filter="FORWARD/BACK" place="server">
99 * local speed = (FORWARD - BACK) * 5;
100 * velocity = testbody:getLinearVelocity();
101 * velocity.z = speed;
102 * testbody:setLinearVelocity();
103 * </link>
104 * \endcode
105 * \subsection networking Networking
106 * The engine provides a at the moment still rather simple client-server networking
107 * system. Physics and entities are automatically updated, the same applies to
108 * links which for example are triggered by a client input event, but execute a
109 * server script.
111 * This software is still in its early stages of development, so there might be
112 * and possible are still security leaks in it. Also it doesn't yet have network
113 * encryption or compression and also still breaks quickly when it runs out of
114 * bandwidth.
115 * \subsection examples Examples
116 * There exist 2 examples for the engine: There is a simple test for some functions
117 * of it in tests/test1, and there is a simple helicopter game in tests/gunships
118 * which shows how to write a simple game using the engine.
123 * \brief Namespace which holds all the classes of the engine
125 namespace peak
127 class Plugin;
130 * \brief Main game engine class. Calls the other parts of the engine.
132 class GameEngine
134 public:
136 * \brief Returns pointer to the GameEngine class.
138 * \return Pointer to the game engine
140 static GameEngine *get(void);
143 * \brief Initializes the other parts of the engine and starts the game.
145 * Returns when the engine has been closed.
146 * \param root Path to the data of the game
147 * \return Returns false if there have been errors, else returns true.
149 bool run(std::string root);
152 * \brief Stops the game forcefully at the next frame
154 void stopGame(void);
157 * \brief Sets the root directory.
159 * Do not use this function!
161 void setRootDirectory(std::string dir);
163 * \brief Returns the root directory specified by run().
165 * \return Engine's root directory
167 std::string getRootDirectory(void);
168 private:
169 GameEngine();
171 std::string rootdir;
173 bool stopengine;
175 double lastframe;
179 #endif