#ifndef ENGINE_H__ #define ENGINE_H__ #include "define.h" #include "openglcontext.h" #include "texture.h" #include "transformation.h" #include "shader.h" #include "player.h" #include "chunk.h" #include "skybox.h" #include "audio.h" #include "textureatlas.h" #include "blockinfo.h" #include "array2d.h" #include "world.h" #include "perlin.h" class Engine : public OpenglContext { public: Engine(); virtual ~Engine(); virtual void Init(); virtual void DeInit(); virtual void LoadResource(); virtual void UnloadResource(); virtual void Render(float elapsedTime); virtual void KeyPressEvent(unsigned char key); virtual void KeyReleaseEvent(unsigned char key); virtual void MouseMoveEvent(int x, int y); virtual void MousePressEvent(const MOUSE_BUTTON &button, int x, int y); virtual void MouseReleaseEvent(const MOUSE_BUTTON &button, int x, int y); private: bool LoadTexture(Texture& texture, const std::string& filename, bool stopOnError = true); void DrawHud(float elapsedTime); void PrintText(unsigned int x, unsigned int y, const std::string& t); int GetFps(float elapsedTime) const; bool GenerateChunk(int chx, int chy); void UpdateWorld(int& generates, int& updates, int chx, int chy); void ChangeBlockAtCursor(BlockType blocktype); bool m_wireframe = false; bool m_renderer = false; int m_renderCount = 0; int m_badHitCount = 0; std::vector m_renderManifest; BlockInfo* m_blockinfo[BTYPE_LAST]; TextureAtlas m_textureAtlas = TextureAtlas(BTYPE_LAST); World m_world = World(); Perlin m_perlin = Perlin(3,5.f,64.f,12345); Texture m_textureFloor; Texture m_textureSkybox; Texture m_textureFont; Texture m_textureCrosshair; Texture m_textureCube1; Skybox m_skybox; Shader m_shader01; Audio m_audio = Audio(AUDIO_PATH "music01.wav"); Player m_player = Player(Vector3f(CHUNK_SIZE_X * WORLD_SIZE_X / 2, CHUNK_SIZE_Y + 1.8f, CHUNK_SIZE_Z * WORLD_SIZE_X / 2)); bool m_keyW = false; bool m_keyA = false; bool m_keyS = false; bool m_keyD = false; bool m_keylshift = false; bool m_keySpace = false; bool m_mouseL = false; bool m_mouseR = false; bool m_mouseC = false; bool m_mouseWU = false; bool m_mouseWD = false; bool m_block = false; }; template static bool EqualWithEpsilon(const T& v1, const T& v2, T epsilon = T(0.0001)) { return (fabs(v2 - v1) < epsilon); } template static bool InRangeWithEpsilon(const T& v, const T& vinf, const T& vsup, T epsilon = T(0.0001)) { return (v >= vinf - epsilon && v <= vsup + epsilon); } #endif // ENGINE_H__