From: RĂ©mi Verschelde Date: Sun, 11 Dec 2016 14:06:33 +0000 (+0100) Subject: Rename all C++ headers with .hpp extension X-Git-Url: https://git.jsancho.org/?a=commitdiff_plain;h=ed3662c0852c4312a612b4fc35bd03aba8d13db7;hp=b84825978803615f45a9f128232e62431042aec0;p=lugaru.git Rename all C++ headers with .hpp extension Also improve header inclusion to follow this logic: - "Own" header comes first (`Folders.hpp` in `Folder.cpp`) - Lugaru headers come next, in alphabetical order - System headers come next, using the `
` format --- diff --git a/CMakeLists.txt b/CMakeLists.txt index 62a62f2..6faa895 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -86,42 +86,42 @@ set(LUGARU_SRCS ) set(LUGARU_H - ${SRCDIR}/Animation/Animation.h - ${SRCDIR}/Animation/Joint.h - ${SRCDIR}/Animation/Muscle.h - ${SRCDIR}/Animation/Skeleton.h - ${SRCDIR}/Audio/openal_wrapper.h - ${SRCDIR}/Audio/Sounds.h - ${SRCDIR}/Devtools/ConsoleCmds.h - ${SRCDIR}/Environment/Lights.h - ${SRCDIR}/Environment/Skybox.h - ${SRCDIR}/Environment/Terrain.h - ${SRCDIR}/Graphic/gamegl.h - ${SRCDIR}/Graphic/Models.h - ${SRCDIR}/Graphic/Sprite.h - ${SRCDIR}/Graphic/Stereo.h - ${SRCDIR}/Graphic/Text.h - ${SRCDIR}/Graphic/Texture.h - ${SRCDIR}/Level/Campaign.h - ${SRCDIR}/Level/Dialog.h - ${SRCDIR}/Level/Hotspot.h - ${SRCDIR}/Math/Frustum.h - ${SRCDIR}/Math/PhysicsMath.h - ${SRCDIR}/Math/Quaternions.h - ${SRCDIR}/Math/Random.h - ${SRCDIR}/Menu/Menu.h - ${SRCDIR}/Objects/Objects.h - ${SRCDIR}/Objects/Person.h - ${SRCDIR}/Objects/Weapons.h + ${SRCDIR}/Animation/Animation.hpp + ${SRCDIR}/Animation/Joint.hpp + ${SRCDIR}/Animation/Muscle.hpp + ${SRCDIR}/Animation/Skeleton.hpp + ${SRCDIR}/Audio/openal_wrapper.hpp + ${SRCDIR}/Audio/Sounds.hpp + ${SRCDIR}/Devtools/ConsoleCmds.hpp + ${SRCDIR}/Environment/Lights.hpp + ${SRCDIR}/Environment/Skybox.hpp + ${SRCDIR}/Environment/Terrain.hpp + ${SRCDIR}/Graphic/gamegl.hpp + ${SRCDIR}/Graphic/Models.hpp + ${SRCDIR}/Graphic/Sprite.hpp + ${SRCDIR}/Graphic/Stereo.hpp + ${SRCDIR}/Graphic/Text.hpp + ${SRCDIR}/Graphic/Texture.hpp + ${SRCDIR}/Level/Campaign.hpp + ${SRCDIR}/Level/Dialog.hpp + ${SRCDIR}/Level/Hotspot.hpp + ${SRCDIR}/Math/Frustum.hpp + ${SRCDIR}/Math/PhysicsMath.hpp + ${SRCDIR}/Math/Quaternions.hpp + ${SRCDIR}/Math/Random.hpp + ${SRCDIR}/Menu/Menu.hpp + ${SRCDIR}/Objects/Objects.hpp + ${SRCDIR}/Objects/Person.hpp + ${SRCDIR}/Objects/Weapons.hpp ${SRCDIR}/Thirdparty/optionparser.h - ${SRCDIR}/User/Account.h - ${SRCDIR}/User/Settings.h + ${SRCDIR}/User/Account.hpp + ${SRCDIR}/User/Settings.hpp ${SRCDIR}/Utils/binio.h - ${SRCDIR}/Utils/Folders.h - ${SRCDIR}/Utils/ImageIO.h - ${SRCDIR}/Utils/Input.h + ${SRCDIR}/Utils/Folders.hpp + ${SRCDIR}/Utils/ImageIO.hpp + ${SRCDIR}/Utils/Input.hpp ${SRCDIR}/Utils/private.h - ${SRCDIR}/Game.h + ${SRCDIR}/Game.hpp ) @@ -132,7 +132,7 @@ if(UNIX) ) set(LUGARU_H ${LUGARU_H} - ${SRCDIR}/MacCompatibility.h + ${SRCDIR}/MacCompatibility.hpp ) endif(UNIX) @@ -152,8 +152,8 @@ if(WIN32) set(LUGARU_H ${LUGARU_H} - ${SRCDIR}/WinDefs.h - ${SRCDIR}/win-res/resource.h) + ${SRCDIR}/WinDefs.hpp + ${SRCDIR}/win-res/resource.hpp) endif(WIN32) if(APPLE) diff --git a/Source/Animation/Animation.cpp b/Source/Animation/Animation.cpp index 4433800..27b82ad 100644 --- a/Source/Animation/Animation.cpp +++ b/Source/Animation/Animation.cpp @@ -17,10 +17,11 @@ You should have received a copy of the GNU General Public License along with Lugaru. If not, see . */ -#include "Animation/Animation.h" -#include "Animation/Skeleton.h" -#include "Utils/Folders.h" -#include "Game.h" +#include "Animation/Animation.hpp" + +#include "Animation/Skeleton.hpp" +#include "Game.hpp" +#include "Utils/Folders.hpp" extern bool visibleloading; diff --git a/Source/Animation/Animation.h b/Source/Animation/Animation.h deleted file mode 100644 index 91205ab..0000000 --- a/Source/Animation/Animation.h +++ /dev/null @@ -1,99 +0,0 @@ -/* -Copyright (C) 2010-2016 - Lugaru contributors (see AUTHORS file) - -This file is part of Lugaru. - -Lugaru is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2 of the License, or -(at your option) any later version. - -Lugaru is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with Lugaru. If not, see . -*/ - -#ifndef ANIMATION_H -#define ANIMATION_H - -#include -#include "Math/Quaternions.h" - -enum anim_attack_type { - neutral, normalattack, reversed, reversal -}; - -enum anim_height_type { - lowheight, middleheight, highheight -}; - -enum animation_types { -#define DECLARE_ANIM(id, ...) id, -#include "Animation.def" -#undef DECLARE_ANIM - animation_count -}; - -enum animation_bit_offsets { -#define DECLARE_ANIM_BIT(bit) o_##bit, -#include "Animation.def" -#undef DECLARE_ANIM_BIT - animation_bit_count -}; - -enum animation_bits_def { -#define DECLARE_ANIM_BIT(bit) bit = 1 << o_##bit, -#include "Animation.def" -#undef DECLARE_ANIM_BIT -}; - -static const int animation_bits[animation_count] = { -#define DECLARE_ANIM(id, name, height, type, bits) bits, -#include "Animation.def" -#undef DECLARE_ANIM -}; - -struct AnimationFrameJointInfo -{ - XYZ position; - float twist; - float twist2; - bool onground; -}; - -struct AnimationFrame -{ - void loadBaseInfo(FILE* tfile); - void loadTwist2(FILE* tfile); - void loadLabel(FILE* tfile); - void loadWeaponTarget(FILE* tfile); - - std::vector joints; - XYZ forward; - int label; - XYZ weapontarget; - float speed; -}; - -class Animation -{ -public: - static std::vector animations; - static void loadAll(); - - anim_height_type height; - anim_attack_type attack; - int numjoints; - - std::vector frames; - - XYZ offset; - - Animation(); - Animation(const std::string& fileName, anim_height_type aheight, anim_attack_type aattack); -}; -#endif diff --git a/Source/Animation/Animation.hpp b/Source/Animation/Animation.hpp new file mode 100644 index 0000000..b58f6ba --- /dev/null +++ b/Source/Animation/Animation.hpp @@ -0,0 +1,100 @@ +/* +Copyright (C) 2010-2016 - Lugaru contributors (see AUTHORS file) + +This file is part of Lugaru. + +Lugaru is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +Lugaru is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with Lugaru. If not, see . +*/ + +#ifndef _ANIMATION_HPP_ +#define _ANIMATION_HPP_ + +#include "Math/Quaternions.hpp" + +#include + +enum anim_attack_type { + neutral, normalattack, reversed, reversal +}; + +enum anim_height_type { + lowheight, middleheight, highheight +}; + +enum animation_types { +#define DECLARE_ANIM(id, ...) id, +#include "Animation.def" +#undef DECLARE_ANIM + animation_count +}; + +enum animation_bit_offsets { +#define DECLARE_ANIM_BIT(bit) o_##bit, +#include "Animation.def" +#undef DECLARE_ANIM_BIT + animation_bit_count +}; + +enum animation_bits_def { +#define DECLARE_ANIM_BIT(bit) bit = 1 << o_##bit, +#include "Animation.def" +#undef DECLARE_ANIM_BIT +}; + +static const int animation_bits[animation_count] = { +#define DECLARE_ANIM(id, name, height, type, bits) bits, +#include "Animation.def" +#undef DECLARE_ANIM +}; + +struct AnimationFrameJointInfo +{ + XYZ position; + float twist; + float twist2; + bool onground; +}; + +struct AnimationFrame +{ + void loadBaseInfo(FILE* tfile); + void loadTwist2(FILE* tfile); + void loadLabel(FILE* tfile); + void loadWeaponTarget(FILE* tfile); + + std::vector joints; + XYZ forward; + int label; + XYZ weapontarget; + float speed; +}; + +class Animation +{ +public: + static std::vector animations; + static void loadAll(); + + anim_height_type height; + anim_attack_type attack; + int numjoints; + + std::vector frames; + + XYZ offset; + + Animation(); + Animation(const std::string& fileName, anim_height_type aheight, anim_attack_type aattack); +}; +#endif diff --git a/Source/Animation/Joint.cpp b/Source/Animation/Joint.cpp index 4428cb8..f615bfe 100644 --- a/Source/Animation/Joint.cpp +++ b/Source/Animation/Joint.cpp @@ -18,7 +18,8 @@ You should have received a copy of the GNU General Public License along with Lugaru. If not, see . */ -#include "Animation/Joint.h" +#include "Animation/Joint.hpp" + #include "Utils/binio.h" Joint::Joint() : diff --git a/Source/Animation/Joint.h b/Source/Animation/Joint.h deleted file mode 100644 index 124d7a6..0000000 --- a/Source/Animation/Joint.h +++ /dev/null @@ -1,64 +0,0 @@ -/* -Copyright (C) 2003, 2010 - Wolfire Games -Copyright (C) 2010-2016 - Lugaru contributors (see AUTHORS file) - -This file is part of Lugaru. - -Lugaru is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2 of the License, or -(at your option) any later version. - -Lugaru is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with Lugaru. If not, see . -*/ - -#ifndef _JOINT_H_ -#define _JOINT_H_ - -#include "Math/Quaternions.h" -#include - -enum bodypart { - head, neck, - leftshoulder, leftelbow, leftwrist, lefthand, - rightshoulder, rightelbow, rightwrist, righthand, - abdomen, lefthip, righthip, groin, - leftknee, leftankle, leftfoot, - rightknee, rightankle, rightfoot -}; - -class Joint -{ -public: - XYZ position; - XYZ oldposition; - XYZ realoldposition; - XYZ velocity; - XYZ oldvelocity; - XYZ startpos; - float blurred; - float length; - float mass; - bool lower; - bool hasparent; - bool locked; - int modelnum; - bool visible; - Joint* parent; - bool sametwist; - bodypart label; - int hasgun; - float delay; - XYZ velchange; - - Joint(); - void load(FILE* tfile, std::vector& joints); -}; - -#endif diff --git a/Source/Animation/Joint.hpp b/Source/Animation/Joint.hpp new file mode 100644 index 0000000..4b4f221 --- /dev/null +++ b/Source/Animation/Joint.hpp @@ -0,0 +1,65 @@ +/* +Copyright (C) 2003, 2010 - Wolfire Games +Copyright (C) 2010-2016 - Lugaru contributors (see AUTHORS file) + +This file is part of Lugaru. + +Lugaru is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +Lugaru is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with Lugaru. If not, see . +*/ + +#ifndef _JOINT_HPP_ +#define _JOINT_HPP_ + +#include "Math/Quaternions.hpp" + +#include + +enum bodypart { + head, neck, + leftshoulder, leftelbow, leftwrist, lefthand, + rightshoulder, rightelbow, rightwrist, righthand, + abdomen, lefthip, righthip, groin, + leftknee, leftankle, leftfoot, + rightknee, rightankle, rightfoot +}; + +class Joint +{ +public: + XYZ position; + XYZ oldposition; + XYZ realoldposition; + XYZ velocity; + XYZ oldvelocity; + XYZ startpos; + float blurred; + float length; + float mass; + bool lower; + bool hasparent; + bool locked; + int modelnum; + bool visible; + Joint* parent; + bool sametwist; + bodypart label; + int hasgun; + float delay; + XYZ velchange; + + Joint(); + void load(FILE* tfile, std::vector& joints); +}; + +#endif diff --git a/Source/Animation/Muscle.cpp b/Source/Animation/Muscle.cpp index c4f201a..4485c5e 100644 --- a/Source/Animation/Muscle.cpp +++ b/Source/Animation/Muscle.cpp @@ -18,7 +18,8 @@ You should have received a copy of the GNU General Public License along with Lugaru. If not, see . */ -#include "Animation/Muscle.h" +#include "Animation/Muscle.hpp" + #include "Utils/binio.h" extern float multiplier; diff --git a/Source/Animation/Muscle.h b/Source/Animation/Muscle.h deleted file mode 100644 index a286928..0000000 --- a/Source/Animation/Muscle.h +++ /dev/null @@ -1,57 +0,0 @@ -/* -Copyright (C) 2003, 2010 - Wolfire Games -Copyright (C) 2010-2016 - Lugaru contributors (see AUTHORS file) - -This file is part of Lugaru. - -Lugaru is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2 of the License, or -(at your option) any later version. - -Lugaru is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with Lugaru. If not, see . -*/ - -#ifndef _MUSCLE_H_ -#define _MUSCLE_H_ - -#include -#include "Animation/Joint.h" - -enum muscle_type {boneconnect, constraint, muscle}; - -class Muscle -{ -public: - std::vector vertices; - std::vector verticeslow; - std::vector verticesclothes; - float length; - float targetlength; - Joint* parent1; - Joint* parent2; - float maxlength; - float minlength; - muscle_type type; - bool visible; - float rotate1, rotate2, rotate3; - float lastrotate1, lastrotate2, lastrotate3; - float oldrotate1, oldrotate2, oldrotate3; - float newrotate1, newrotate2, newrotate3; - - float strength; - - Muscle(); - void load(FILE* tfile, int vertexNum, std::vector& joints); - void loadVerticesLow(FILE* tfile, int vertexNum); - void loadVerticesClothes(FILE* tfile, int vertexNum); - void DoConstraint(bool spinny); -}; - -#endif diff --git a/Source/Animation/Muscle.hpp b/Source/Animation/Muscle.hpp new file mode 100644 index 0000000..d3ea815 --- /dev/null +++ b/Source/Animation/Muscle.hpp @@ -0,0 +1,58 @@ +/* +Copyright (C) 2003, 2010 - Wolfire Games +Copyright (C) 2010-2016 - Lugaru contributors (see AUTHORS file) + +This file is part of Lugaru. + +Lugaru is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +Lugaru is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with Lugaru. If not, see . +*/ + +#ifndef _MUSCLE_HPP_ +#define _MUSCLE_HPP_ + +#include "Animation/Joint.hpp" + +#include + +enum muscle_type {boneconnect, constraint, muscle}; + +class Muscle +{ +public: + std::vector vertices; + std::vector verticeslow; + std::vector verticesclothes; + float length; + float targetlength; + Joint* parent1; + Joint* parent2; + float maxlength; + float minlength; + muscle_type type; + bool visible; + float rotate1, rotate2, rotate3; + float lastrotate1, lastrotate2, lastrotate3; + float oldrotate1, oldrotate2, oldrotate3; + float newrotate1, newrotate2, newrotate3; + + float strength; + + Muscle(); + void load(FILE* tfile, int vertexNum, std::vector& joints); + void loadVerticesLow(FILE* tfile, int vertexNum); + void loadVerticesClothes(FILE* tfile, int vertexNum); + void DoConstraint(bool spinny); +}; + +#endif diff --git a/Source/Animation/Skeleton.cpp b/Source/Animation/Skeleton.cpp index f525240..3f5e65c 100644 --- a/Source/Animation/Skeleton.cpp +++ b/Source/Animation/Skeleton.cpp @@ -18,12 +18,12 @@ You should have received a copy of the GNU General Public License along with Lugaru. If not, see . */ -/**> HEADER FILES <**/ -#include "Game.h" -#include "Animation/Animation.h" -#include "Animation/Skeleton.h" -#include "Audio/openal_wrapper.h" -#include "Utils/Folders.h" +#include "Animation/Skeleton.hpp" + +#include "Animation/Animation.hpp" +#include "Audio/openal_wrapper.hpp" +#include "Game.hpp" +#include "Utils/Folders.hpp" extern float multiplier; extern float gravity; diff --git a/Source/Animation/Skeleton.h b/Source/Animation/Skeleton.h deleted file mode 100644 index 19db503..0000000 --- a/Source/Animation/Skeleton.h +++ /dev/null @@ -1,101 +0,0 @@ -/* -Copyright (C) 2003, 2010 - Wolfire Games -Copyright (C) 2010-2016 - Lugaru contributors (see AUTHORS file) - -This file is part of Lugaru. - -Lugaru is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2 of the License, or -(at your option) any later version. - -Lugaru is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with Lugaru. If not, see . -*/ - -#ifndef _SKELETON_H_ -#define _SKELETON_H_ - -/**> HEADER FILES <**/ -#include "Animation/Animation.h" -#include "Animation/Joint.h" -#include "Animation/Muscle.h" -#include "Graphic/gamegl.h" -#include "Graphic/Models.h" -#include "Graphic/Sprite.h" -#include "Math/Quaternions.h" -#include "Objects/Objects.h" -#include "Utils/binio.h" - -const int max_joints = 50; - -class Skeleton -{ -public: - std::vector joints; - - std::vector muscles; - - int selected; - - int forwardjoints[3]; - XYZ forward; - - int id; - - int lowforwardjoints[3]; - XYZ lowforward; - - XYZ specialforward[5]; - int jointlabels[max_joints]; - - Model model[7]; - Model modellow; - Model modelclothes; - int num_models; - - Model drawmodel; - Model drawmodellow; - Model drawmodelclothes; - - bool clothes; - bool spinny; - - GLubyte skinText[512 * 512 * 3]; - int skinsize; - - float checkdelay; - - float longdead; - bool broken; - - int free; - int oldfree; - float freetime; - bool freefall; - - void FindForwards(); - float DoConstraints(XYZ *coords, float *scale); - void DoGravity(float *scale); - void FindRotationJoint(int which); - void FindRotationJointSameTwist(int which); - void FindRotationMuscle(int which, int animation); - void Load(const std::string& fileName, const std::string& lowfileName, const std::string& clothesfileName, const std::string& modelfileName, const std::string& model2fileName, const std::string& model3fileName, const std::string& model4fileName, const std::string& model5fileNamee, const std::string& model6fileName, const std::string& model7fileName, const std::string& modellowfileName, const std::string& modelclothesfileName, bool aclothes); - - Skeleton(); - -private: - // convenience functions - // only for Skeleton.cpp - inline Joint& joint(int bodypart) { return joints[jointlabels[bodypart]]; } - inline XYZ& jointPos(int bodypart) { return joint(bodypart).position; } - inline XYZ& jointVel(int bodypart) { return joint(bodypart).velocity; } - -}; - -#endif diff --git a/Source/Animation/Skeleton.hpp b/Source/Animation/Skeleton.hpp new file mode 100644 index 0000000..6685062 --- /dev/null +++ b/Source/Animation/Skeleton.hpp @@ -0,0 +1,100 @@ +/* +Copyright (C) 2003, 2010 - Wolfire Games +Copyright (C) 2010-2016 - Lugaru contributors (see AUTHORS file) + +This file is part of Lugaru. + +Lugaru is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +Lugaru is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with Lugaru. If not, see . +*/ + +#ifndef _SKELETON_HPP_ +#define _SKELETON_HPP_ + +#include "Animation/Animation.hpp" +#include "Animation/Joint.hpp" +#include "Animation/Muscle.hpp" +#include "Graphic/gamegl.hpp" +#include "Graphic/Models.hpp" +#include "Graphic/Sprite.hpp" +#include "Math/Quaternions.hpp" +#include "Objects/Objects.hpp" +#include "Utils/binio.h" + +const int max_joints = 50; + +class Skeleton +{ +public: + std::vector joints; + + std::vector muscles; + + int selected; + + int forwardjoints[3]; + XYZ forward; + + int id; + + int lowforwardjoints[3]; + XYZ lowforward; + + XYZ specialforward[5]; + int jointlabels[max_joints]; + + Model model[7]; + Model modellow; + Model modelclothes; + int num_models; + + Model drawmodel; + Model drawmodellow; + Model drawmodelclothes; + + bool clothes; + bool spinny; + + GLubyte skinText[512 * 512 * 3]; + int skinsize; + + float checkdelay; + + float longdead; + bool broken; + + int free; + int oldfree; + float freetime; + bool freefall; + + void FindForwards(); + float DoConstraints(XYZ *coords, float *scale); + void DoGravity(float *scale); + void FindRotationJoint(int which); + void FindRotationJointSameTwist(int which); + void FindRotationMuscle(int which, int animation); + void Load(const std::string& fileName, const std::string& lowfileName, const std::string& clothesfileName, const std::string& modelfileName, const std::string& model2fileName, const std::string& model3fileName, const std::string& model4fileName, const std::string& model5fileNamee, const std::string& model6fileName, const std::string& model7fileName, const std::string& modellowfileName, const std::string& modelclothesfileName, bool aclothes); + + Skeleton(); + +private: + // convenience functions + // only for Skeleton.cpp + inline Joint& joint(int bodypart) { return joints[jointlabels[bodypart]]; } + inline XYZ& jointPos(int bodypart) { return joint(bodypart).position; } + inline XYZ& jointVel(int bodypart) { return joint(bodypart).velocity; } + +}; + +#endif diff --git a/Source/Audio/Sounds.cpp b/Source/Audio/Sounds.cpp index 2e47da0..063e0c8 100644 --- a/Source/Audio/Sounds.cpp +++ b/Source/Audio/Sounds.cpp @@ -17,10 +17,10 @@ You should have received a copy of the GNU General Public License along with Lugaru. If not, see . */ -#include "Audio/openal_wrapper.h" -#include "Audio/Sounds.h" -#include "Math/Quaternions.h" -#include "Utils/Folders.h" +#include "Audio/Sounds.hpp" + +#include "Audio/openal_wrapper.hpp" +#include "Utils/Folders.hpp" struct OPENAL_SAMPLE *samp[sounds_count]; diff --git a/Source/Audio/Sounds.h b/Source/Audio/Sounds.h deleted file mode 100644 index 7557993..0000000 --- a/Source/Audio/Sounds.h +++ /dev/null @@ -1,45 +0,0 @@ -/* -Copyright (C) 2010-2016 - Lugaru contributors (see AUTHORS file) - -This file is part of Lugaru. - -Lugaru is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2 of the License, or -(at your option) any later version. - -Lugaru is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with Lugaru. If not, see . -*/ - -#ifndef SOUNDS_H -#define SOUNDS_H - -enum sound_types { -#define DECLARE_SOUND(id, filename) id, -#include "Sounds.def" -#undef DECLARE_SOUND - sounds_count -}; - -extern struct OPENAL_SAMPLE *samp[sounds_count]; -extern int channels[]; - -extern void loadAllSounds(); - -extern void addEnvSound(XYZ coords, float vol = 16, float life = .4); - -extern void emit_sound_at(int soundid, const XYZ &pos = XYZ(), float vol = 256.f); -extern void emit_sound_np(int soundid, float vol = 256.f); -extern void emit_stream_at(int soundid, const XYZ &pos = XYZ(), float vol = 256.f); -extern void emit_stream_np(int soundid, float vol = 256.f); -extern void resume_stream(int soundid); -extern void pause_sound(int soundid); - -extern int footstepsound, footstepsound2, footstepsound3, footstepsound4; -#endif diff --git a/Source/Audio/Sounds.hpp b/Source/Audio/Sounds.hpp new file mode 100644 index 0000000..1ec3139 --- /dev/null +++ b/Source/Audio/Sounds.hpp @@ -0,0 +1,47 @@ +/* +Copyright (C) 2010-2016 - Lugaru contributors (see AUTHORS file) + +This file is part of Lugaru. + +Lugaru is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +Lugaru is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with Lugaru. If not, see . +*/ + +#ifndef _SOUNDS_HPP_ +#define _SOUNDS_HPP_ + +#include "Math/Quaternions.hpp" + +enum sound_types { +#define DECLARE_SOUND(id, filename) id, +#include "Sounds.def" +#undef DECLARE_SOUND + sounds_count +}; + +extern struct OPENAL_SAMPLE *samp[sounds_count]; +extern int channels[]; + +extern void loadAllSounds(); + +extern void addEnvSound(XYZ coords, float vol = 16, float life = .4); + +extern void emit_sound_at(int soundid, const XYZ &pos = XYZ(), float vol = 256.f); +extern void emit_sound_np(int soundid, float vol = 256.f); +extern void emit_stream_at(int soundid, const XYZ &pos = XYZ(), float vol = 256.f); +extern void emit_stream_np(int soundid, float vol = 256.f); +extern void resume_stream(int soundid); +extern void pause_sound(int soundid); + +extern int footstepsound, footstepsound2, footstepsound3, footstepsound4; +#endif diff --git a/Source/Audio/openal_wrapper.cpp b/Source/Audio/openal_wrapper.cpp index e1e2346..bcc5d73 100644 --- a/Source/Audio/openal_wrapper.cpp +++ b/Source/Audio/openal_wrapper.cpp @@ -18,15 +18,16 @@ You should have received a copy of the GNU General Public License along with Lugaru. If not, see . */ +#include "Audio/openal_wrapper.hpp" + +#include "Audio/Sounds.hpp" +#include "Game.hpp" +#include "Math/Quaternions.hpp" + #include #include #include -#include "Math/Quaternions.h" -#include "Audio/openal_wrapper.h" -#include "Audio/Sounds.h" -#include "Game.h" - extern float slomofreq; // NOTE: diff --git a/Source/Audio/openal_wrapper.h b/Source/Audio/openal_wrapper.h deleted file mode 100644 index b8de914..0000000 --- a/Source/Audio/openal_wrapper.h +++ /dev/null @@ -1,113 +0,0 @@ -/* -Copyright (C) 2003, 2010 - Wolfire Games -Copyright (C) 2010-2016 - Lugaru contributors (see AUTHORS file) - -This file is part of Lugaru. - -Lugaru is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2 of the License, or -(at your option) any later version. - -Lugaru is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with Lugaru. If not, see . -*/ - -#ifndef OPENAL_WRAPPER_H -#define OPENAL_WRAPPER_H - -#ifdef _WIN32 -#include -#endif - -#include "AL/al.h" -#include "AL/alc.h" - -#include "ogg/ogg.h" -#include "vorbis/vorbisfile.h" - -#include "Math/Quaternions.h" -#include "MacCompatibility.h" - -#if 0 /* this should only be enable if OPENAL doesn't provide AL_API on all platforms */ -#if (!defined(WIN32) && !defined(_WIN32) && !defined(__WIN32__) && !defined(_WIN64) && !defined(_WIN32_WCE) && !defined(_XBOX)) || (defined(__GNUC__) && defined(WIN32)) -#ifndef __cdecl -#define __cdecl -#endif -#ifndef __stdcall -#define __stdcall -#endif -#endif - -#if defined(_WIN32_WCE) -#define AL_API _cdecl -#define F_CALLBACKAPI _cdecl -#else -#define AL_API __stdcall -#define F_CALLBACKAPI __stdcall -#endif - -#ifdef DLL_EXPORTS -#define DLL_API __declspec(dllexport) -#else -#if defined(__LCC__) || defined(__MINGW32__) || defined(__CYGWIN32__) -#define DLL_API AL_API -#else -#define DLL_API -#endif /* __LCC__ || __MINGW32__ || __CYGWIN32__ */ -#endif /* DLL_EXPORTS */ -#endif /* if 0 */ - - -typedef struct OPENAL_SAMPLE OPENAL_SAMPLE; -typedef OPENAL_SAMPLE OPENAL_STREAM; -typedef struct OPENAL_DSPUNIT OPENAL_DSPUNIT; - -enum OPENAL_OUTPUTTYPES { - OPENAL_OUTPUT_NOSOUND, /* NoSound driver, all calls to this succeed but do nothing. */ - OPENAL_OUTPUT_OSS, /* Linux/Unix OSS (Open Sound System) driver, i.e. the kernel sound drivers. */ - OPENAL_OUTPUT_ALSA, /* Linux Alsa driver. */ -}; - -#define OPENAL_LOOP_OFF 0x00000001 /* For non looping samples. */ -#define OPENAL_LOOP_NORMAL 0x00000002 /* For forward looping samples. */ -#define OPENAL_HW3D 0x00001000 /* Attempts to make samples use 3d hardware acceleration. (if the card supports it) */ -#define OPENAL_2D 0x00002000 /* Tells software (not hardware) based sample not to be included in 3d processing. */ -#define OPENAL_FREE -1 /* value to play on any free channel, or to allocate a sample in a free sample slot. */ -#define OPENAL_ALL -3 /* for a channel index , this flag will affect ALL channels available! Not supported by every function. */ - -#ifdef __cplusplus -extern "C" { -#endif - -#undef AL_API -#define AL_API - - AL_API void OPENAL_3D_Listener_SetAttributes(const float *pos, const float *vel, float fx, float fy, float fz, float tx, float ty, float tz); - AL_API signed char OPENAL_3D_SetAttributes(int channel, const float *pos, const float *vel); - AL_API signed char OPENAL_3D_SetAttributes_(int channel, const XYZ &pos, const float *vel); - AL_API signed char OPENAL_Init(int mixrate, int maxsoftwarechannels, unsigned int flags); - AL_API void OPENAL_Close(); - AL_API OPENAL_SAMPLE *OPENAL_Sample_Load(int index, const char *name_or_data, unsigned int mode, int offset, int length); - AL_API void OPENAL_Sample_Free(OPENAL_SAMPLE *sptr); - AL_API signed char OPENAL_SetFrequency(int channel, bool slomo = false); - AL_API signed char OPENAL_SetVolume(int channel, int vol); - AL_API signed char OPENAL_SetPaused(int channel, signed char paused); - AL_API void OPENAL_SetSFXMasterVolume(int volume); - AL_API signed char OPENAL_StopSound(int channel); - AL_API signed char OPENAL_Stream_SetMode(OPENAL_STREAM *stream, unsigned int mode); - AL_API void OPENAL_Update(); - AL_API signed char OPENAL_SetOutput(int outputtype); - void PlaySoundEx(int chan, OPENAL_SAMPLE *sptr, OPENAL_DSPUNIT *dsp, signed char startpaused); - void PlayStreamEx(int chan, OPENAL_SAMPLE *sptr, OPENAL_DSPUNIT *dsp, signed char startpaused); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/Source/Audio/openal_wrapper.hpp b/Source/Audio/openal_wrapper.hpp new file mode 100644 index 0000000..cea4797 --- /dev/null +++ b/Source/Audio/openal_wrapper.hpp @@ -0,0 +1,112 @@ +/* +Copyright (C) 2003, 2010 - Wolfire Games +Copyright (C) 2010-2016 - Lugaru contributors (see AUTHORS file) + +This file is part of Lugaru. + +Lugaru is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +Lugaru is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with Lugaru. If not, see . +*/ + +#ifndef _OPENAL_WRAPPER_HPP_ +#define _OPENAL_WRAPPER_HPP_ + +#include "MacCompatibility.hpp" +#include "Math/Quaternions.hpp" + +#include +#include +#include +#include + +#ifdef _WIN32 +#include +#endif + +#if 0 /* this should only be enable if OPENAL doesn't provide AL_API on all platforms */ +#if (!defined(WIN32) && !defined(_WIN32) && !defined(__WIN32__) && !defined(_WIN64) && !defined(_WIN32_WCE) && !defined(_XBOX)) || (defined(__GNUC__) && defined(WIN32)) +#ifndef __cdecl +#define __cdecl +#endif +#ifndef __stdcall +#define __stdcall +#endif +#endif + +#if defined(_WIN32_WCE) +#define AL_API _cdecl +#define F_CALLBACKAPI _cdecl +#else +#define AL_API __stdcall +#define F_CALLBACKAPI __stdcall +#endif + +#ifdef DLL_EXPORTS +#define DLL_API __declspec(dllexport) +#else +#if defined(__LCC__) || defined(__MINGW32__) || defined(__CYGWIN32__) +#define DLL_API AL_API +#else +#define DLL_API +#endif /* __LCC__ || __MINGW32__ || __CYGWIN32__ */ +#endif /* DLL_EXPORTS */ +#endif /* if 0 */ + + +typedef struct OPENAL_SAMPLE OPENAL_SAMPLE; +typedef OPENAL_SAMPLE OPENAL_STREAM; +typedef struct OPENAL_DSPUNIT OPENAL_DSPUNIT; + +enum OPENAL_OUTPUTTYPES { + OPENAL_OUTPUT_NOSOUND, /* NoSound driver, all calls to this succeed but do nothing. */ + OPENAL_OUTPUT_OSS, /* Linux/Unix OSS (Open Sound System) driver, i.e. the kernel sound drivers. */ + OPENAL_OUTPUT_ALSA, /* Linux Alsa driver. */ +}; + +#define OPENAL_LOOP_OFF 0x00000001 /* For non looping samples. */ +#define OPENAL_LOOP_NORMAL 0x00000002 /* For forward looping samples. */ +#define OPENAL_HW3D 0x00001000 /* Attempts to make samples use 3d hardware acceleration. (if the card supports it) */ +#define OPENAL_2D 0x00002000 /* Tells software (not hardware) based sample not to be included in 3d processing. */ +#define OPENAL_FREE -1 /* value to play on any free channel, or to allocate a sample in a free sample slot. */ +#define OPENAL_ALL -3 /* for a channel index , this flag will affect ALL channels available! Not supported by every function. */ + +#ifdef __cplusplus +extern "C" { +#endif + +#undef AL_API +#define AL_API + + AL_API void OPENAL_3D_Listener_SetAttributes(const float *pos, const float *vel, float fx, float fy, float fz, float tx, float ty, float tz); + AL_API signed char OPENAL_3D_SetAttributes(int channel, const float *pos, const float *vel); + AL_API signed char OPENAL_3D_SetAttributes_(int channel, const XYZ &pos, const float *vel); + AL_API signed char OPENAL_Init(int mixrate, int maxsoftwarechannels, unsigned int flags); + AL_API void OPENAL_Close(); + AL_API OPENAL_SAMPLE *OPENAL_Sample_Load(int index, const char *name_or_data, unsigned int mode, int offset, int length); + AL_API void OPENAL_Sample_Free(OPENAL_SAMPLE *sptr); + AL_API signed char OPENAL_SetFrequency(int channel, bool slomo = false); + AL_API signed char OPENAL_SetVolume(int channel, int vol); + AL_API signed char OPENAL_SetPaused(int channel, signed char paused); + AL_API void OPENAL_SetSFXMasterVolume(int volume); + AL_API signed char OPENAL_StopSound(int channel); + AL_API signed char OPENAL_Stream_SetMode(OPENAL_STREAM *stream, unsigned int mode); + AL_API void OPENAL_Update(); + AL_API signed char OPENAL_SetOutput(int outputtype); + void PlaySoundEx(int chan, OPENAL_SAMPLE *sptr, OPENAL_DSPUNIT *dsp, signed char startpaused); + void PlayStreamEx(int chan, OPENAL_SAMPLE *sptr, OPENAL_DSPUNIT *dsp, signed char startpaused); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/Source/Devtools/ConsoleCmds.cpp b/Source/Devtools/ConsoleCmds.cpp index dc4c275..a65315b 100644 --- a/Source/Devtools/ConsoleCmds.cpp +++ b/Source/Devtools/ConsoleCmds.cpp @@ -18,11 +18,12 @@ You should have received a copy of the GNU General Public License along with Lugaru. If not, see . */ -#include "Game.h" -#include "Devtools/ConsoleCmds.h" -#include "Level/Dialog.h" -#include "Level/Hotspot.h" -#include "Utils/Folders.h" +#include "Devtools/ConsoleCmds.hpp" + +#include "Game.hpp" +#include "Level/Dialog.hpp" +#include "Level/Hotspot.hpp" +#include "Utils/Folders.hpp" const char *cmd_names[cmd_count] = { #define DECLARE_COMMAND(cmd) #cmd, diff --git a/Source/Devtools/ConsoleCmds.h b/Source/Devtools/ConsoleCmds.h deleted file mode 100644 index 9670aa0..0000000 --- a/Source/Devtools/ConsoleCmds.h +++ /dev/null @@ -1,37 +0,0 @@ -/* -Copyright (C) 2003, 2010 - Wolfire Games -Copyright (C) 2010-2016 - Lugaru contributors (see AUTHORS file) - -This file is part of Lugaru. - -Lugaru is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2 of the License, or -(at your option) any later version. - -Lugaru is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with Lugaru. If not, see . -*/ - -typedef void (*console_handler)(const char *args); - -#define DECLARE_COMMAND(cmd) void ch_##cmd(const char *args); -#include "ConsoleCmds.def" -#undef DECLARE_COMMAND - -/* FIXME - This is only to get cmd_count, not very clean */ -enum console_command { -#define DECLARE_COMMAND(cmd) cmd_##cmd, -#include "ConsoleCmds.def" -#undef DECLARE_COMMAND - cmd_count -}; - -extern const char *cmd_names[cmd_count]; - -extern console_handler cmd_handlers[cmd_count]; diff --git a/Source/Devtools/ConsoleCmds.hpp b/Source/Devtools/ConsoleCmds.hpp new file mode 100644 index 0000000..9670aa0 --- /dev/null +++ b/Source/Devtools/ConsoleCmds.hpp @@ -0,0 +1,37 @@ +/* +Copyright (C) 2003, 2010 - Wolfire Games +Copyright (C) 2010-2016 - Lugaru contributors (see AUTHORS file) + +This file is part of Lugaru. + +Lugaru is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +Lugaru is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with Lugaru. If not, see . +*/ + +typedef void (*console_handler)(const char *args); + +#define DECLARE_COMMAND(cmd) void ch_##cmd(const char *args); +#include "ConsoleCmds.def" +#undef DECLARE_COMMAND + +/* FIXME - This is only to get cmd_count, not very clean */ +enum console_command { +#define DECLARE_COMMAND(cmd) cmd_##cmd, +#include "ConsoleCmds.def" +#undef DECLARE_COMMAND + cmd_count +}; + +extern const char *cmd_names[cmd_count]; + +extern console_handler cmd_handlers[cmd_count]; diff --git a/Source/Environment/Lights.cpp b/Source/Environment/Lights.cpp index 17efb4c..d448cd8 100644 --- a/Source/Environment/Lights.cpp +++ b/Source/Environment/Lights.cpp @@ -18,8 +18,7 @@ You should have received a copy of the GNU General Public License along with Lugaru. If not, see . */ -/**> HEADER FILES <**/ -#include "Environment/Lights.h" +#include "Environment/Lights.hpp" void SetUpLight(Light* whichsource, int whichlight) { diff --git a/Source/Environment/Lights.h b/Source/Environment/Lights.h deleted file mode 100644 index ba1fd6c..0000000 --- a/Source/Environment/Lights.h +++ /dev/null @@ -1,50 +0,0 @@ -/* -Copyright (C) 2003, 2010 - Wolfire Games -Copyright (C) 2010-2016 - Lugaru contributors (see AUTHORS file) - -This file is part of Lugaru. - -Lugaru is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2 of the License, or -(at your option) any later version. - -Lugaru is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with Lugaru. If not, see . -*/ - -#ifndef _LIGHTS_H_ -#define _LIGHTS_H_ - - -/**> HEADER FILES <**/ -#include "Graphic/gamegl.h" -#include "Math/Quaternions.h" - -class Light -{ -public: - GLint type; - GLfloat color[3]; - GLfloat ambient[3]; - int attach; - XYZ location; - inline void setColors(GLfloat cr, GLfloat cg, GLfloat cb, - GLfloat ar, GLfloat ag, GLfloat ab) { - color[0] = cr; - color[1] = cg; - color[2] = cb; - ambient[0] = ar; - ambient[1] = ag; - ambient[2] = ab; - } -}; - -void SetUpLight(Light* whichsource, int whichlight); - -#endif diff --git a/Source/Environment/Lights.hpp b/Source/Environment/Lights.hpp new file mode 100644 index 0000000..ca113e0 --- /dev/null +++ b/Source/Environment/Lights.hpp @@ -0,0 +1,48 @@ +/* +Copyright (C) 2003, 2010 - Wolfire Games +Copyright (C) 2010-2016 - Lugaru contributors (see AUTHORS file) + +This file is part of Lugaru. + +Lugaru is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +Lugaru is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with Lugaru. If not, see . +*/ + +#ifndef _LIGHTS_HPP_ +#define _LIGHTS_HPP_ + +#include "Graphic/gamegl.hpp" +#include "Math/Quaternions.hpp" + +class Light +{ +public: + GLint type; + GLfloat color[3]; + GLfloat ambient[3]; + int attach; + XYZ location; + inline void setColors(GLfloat cr, GLfloat cg, GLfloat cb, + GLfloat ar, GLfloat ag, GLfloat ab) { + color[0] = cr; + color[1] = cg; + color[2] = cb; + ambient[0] = ar; + ambient[1] = ag; + ambient[2] = ab; + } +}; + +void SetUpLight(Light* whichsource, int whichlight); + +#endif diff --git a/Source/Environment/Skybox.cpp b/Source/Environment/Skybox.cpp index ce58adf..47bd28a 100644 --- a/Source/Environment/Skybox.cpp +++ b/Source/Environment/Skybox.cpp @@ -18,8 +18,9 @@ You should have received a copy of the GNU General Public License along with Lugaru. If not, see . */ -#include "Environment/Skybox.h" -#include "Game.h" +#include "Environment/Skybox.hpp" + +#include "Game.hpp" extern float viewdistance; extern float blurness; diff --git a/Source/Environment/Skybox.h b/Source/Environment/Skybox.h deleted file mode 100644 index d2b5d72..0000000 --- a/Source/Environment/Skybox.h +++ /dev/null @@ -1,43 +0,0 @@ -/* -Copyright (C) 2003, 2010 - Wolfire Games -Copyright (C) 2010-2016 - Lugaru contributors (see AUTHORS file) - -This file is part of Lugaru. - -Lugaru is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2 of the License, or -(at your option) any later version. - -Lugaru is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with Lugaru. If not, see . -*/ - -#ifndef _SKYBOX_H_ -#define _SKYBOX_H_ - -#include "Graphic/gamegl.h" -#include "Graphic/Texture.h" -#include "Math/Quaternions.h" -#include "Math/Quaternions.h" -#include "Utils/ImageIO.h" - -class SkyBox -{ -public: - Texture front, left, back, right, up, down; - - void load(const std::string& ffront, const std::string& fleft, const std::string& fback, - const std::string& fright, const std::string& fup, const std::string& fdown); - void draw(); - - SkyBox() {} - ~SkyBox(); -}; - -#endif diff --git a/Source/Environment/Skybox.hpp b/Source/Environment/Skybox.hpp new file mode 100644 index 0000000..1a9d36a --- /dev/null +++ b/Source/Environment/Skybox.hpp @@ -0,0 +1,43 @@ +/* +Copyright (C) 2003, 2010 - Wolfire Games +Copyright (C) 2010-2016 - Lugaru contributors (see AUTHORS file) + +This file is part of Lugaru. + +Lugaru is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +Lugaru is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with Lugaru. If not, see . +*/ + +#ifndef _SKYBOX_HPP_ +#define _SKYBOX_HPP_ + +#include "Graphic/gamegl.hpp" +#include "Graphic/Texture.hpp" +#include "Math/Quaternions.hpp" +#include "Math/Quaternions.hpp" +#include "Utils/ImageIO.hpp" + +class SkyBox +{ +public: + Texture front, left, back, right, up, down; + + void load(const std::string& ffront, const std::string& fleft, const std::string& fback, + const std::string& fright, const std::string& fup, const std::string& fdown); + void draw(); + + SkyBox() {} + ~SkyBox(); +}; + +#endif diff --git a/Source/Environment/Terrain.cpp b/Source/Environment/Terrain.cpp index 8c79cd4..164dce3 100644 --- a/Source/Environment/Terrain.cpp +++ b/Source/Environment/Terrain.cpp @@ -18,10 +18,11 @@ You should have received a copy of the GNU General Public License along with Lugaru. If not, see . */ -#include "Game.h" -#include "Environment/Terrain.h" -#include "Objects/Objects.h" -#include "Utils/Folders.h" +#include "Environment/Terrain.hpp" + +#include "Game.hpp" +#include "Objects/Objects.hpp" +#include "Utils/Folders.hpp" extern XYZ viewer; extern float viewdistance; diff --git a/Source/Environment/Terrain.h b/Source/Environment/Terrain.h deleted file mode 100644 index f9319f7..0000000 --- a/Source/Environment/Terrain.h +++ /dev/null @@ -1,133 +0,0 @@ -/* -Copyright (C) 2003, 2010 - Wolfire Games -Copyright (C) 2010-2016 - Lugaru contributors (see AUTHORS file) - -This file is part of Lugaru. - -Lugaru is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2 of the License, or -(at your option) any later version. - -Lugaru is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with Lugaru. If not, see . -*/ - -#ifndef _TERRAIN_H_ -#define _TERRAIN_H_ - -#include "Environment/Lights.h" -#include "Graphic/gamegl.h" -#include "Graphic/Texture.h" -#include "Math/Frustum.h" -#include "Math/Quaternions.h" -#include "Math/Quaternions.h" -#include "Utils/ImageIO.h" - -#define max_terrain_size 256 -#define curr_terrain_size size -#define subdivision 64 -#define max_patch_elements (max_terrain_size/subdivision)*(max_terrain_size/subdivision)*54 - -#define allfirst 0 -#define mixed 1 -#define allsecond 2 - -#define max_decals 1000 - -#define shadowdecal 0 -#define footprintdecal 1 -#define blooddecal 2 -#define blooddecalfast 3 -#define shadowdecalpermanent 4 -#define breakdecal 5 -#define blooddecalslow 6 -#define bodyprintdecal 7 - -#define snowyenvironment 0 -#define grassyenvironment 1 -#define desertenvironment 2 -// -// Model Structures -// - -class Terrain -{ -public: - Texture bloodtexture; - Texture bloodtexture2; - Texture shadowtexture; - Texture footprinttexture; - Texture bodyprinttexture; - Texture breaktexture; - Texture terraintexture; - short size; - - int patchobjectnum[subdivision][subdivision]; - int patchobjects[subdivision][subdivision][300]; - - float scale; - int type; - float heightmap[max_terrain_size + 1][max_terrain_size + 1]; - XYZ normals[max_terrain_size][max_terrain_size]; - XYZ facenormals[max_terrain_size][max_terrain_size]; - XYZ triangles[(max_terrain_size - 1) * (max_terrain_size - 1) * 2][3]; - float colors[max_terrain_size][max_terrain_size][4]; - float opacityother[max_terrain_size][max_terrain_size]; - float texoffsetx[max_terrain_size][max_terrain_size]; - float texoffsety[max_terrain_size][max_terrain_size]; - int numtris[subdivision][subdivision]; - int textureness[subdivision][subdivision]; - - GLfloat vArray[(max_patch_elements)*subdivision*subdivision]; - - bool visible[subdivision][subdivision]; - float avgypatch[subdivision][subdivision]; - float maxypatch[subdivision][subdivision]; - float minypatch[subdivision][subdivision]; - float heightypatch[subdivision][subdivision]; - - int patch_elements; - - float decaltexcoords[max_decals][3][2]; - XYZ decalvertex[max_decals][3]; - int decaltype[max_decals]; - float decalopacity[max_decals]; - float decalrotation[max_decals]; - float decalalivetime[max_decals]; - float decalbrightness[max_decals]; - XYZ decalposition[max_decals]; - int numdecals; - - void AddObject(XYZ where, float radius, int id); - void DeleteDecal(int which); - void MakeDecal(int type, XYZ where, float size, float opacity, float rotation); - void MakeDecalLock(int type, XYZ where, int whichx, int whichy, float size, float opacity, float rotation); - int lineTerrain(XYZ p1, XYZ p2, XYZ *p); - float getHeight(float pointx, float pointz); - float getOpacity(float pointx, float pointz); - XYZ getLighting(float pointx, float pointz); - XYZ getNormal(float pointx, float pointz); - void UpdateVertexArray(int whichx, int whichy); - void UpdateTransparency(int whichx, int whichy); - void UpdateTransparencyother(int whichx, int whichy); - void UpdateTransparencyotherother(int whichx, int whichy); - bool load(const std::string& fileName); - void CalculateNormals(); - void drawdecals(); - void draw(int layer); - void drawpatch(int whichx, int whichy, float opacity); - void drawpatchother(int whichx, int whichy, float opacity); - void drawpatchotherother(int whichx, int whichy, float opacity); - void DoShadows(); - - Terrain(); - ~Terrain(); -}; - -#endif diff --git a/Source/Environment/Terrain.hpp b/Source/Environment/Terrain.hpp new file mode 100644 index 0000000..3c30e3d --- /dev/null +++ b/Source/Environment/Terrain.hpp @@ -0,0 +1,132 @@ +/* +Copyright (C) 2003, 2010 - Wolfire Games +Copyright (C) 2010-2016 - Lugaru contributors (see AUTHORS file) + +This file is part of Lugaru. + +Lugaru is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +Lugaru is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with Lugaru. If not, see . +*/ + +#ifndef _TERRAIN_HPP_ +#define _TERRAIN_HPP_ + +#include "Environment/Lights.hpp" +#include "Graphic/gamegl.hpp" +#include "Graphic/Texture.hpp" +#include "Math/Frustum.hpp" +#include "Math/Quaternions.hpp" +#include "Utils/ImageIO.hpp" + +#define max_terrain_size 256 +#define curr_terrain_size size +#define subdivision 64 +#define max_patch_elements (max_terrain_size/subdivision)*(max_terrain_size/subdivision)*54 + +#define allfirst 0 +#define mixed 1 +#define allsecond 2 + +#define max_decals 1000 + +#define shadowdecal 0 +#define footprintdecal 1 +#define blooddecal 2 +#define blooddecalfast 3 +#define shadowdecalpermanent 4 +#define breakdecal 5 +#define blooddecalslow 6 +#define bodyprintdecal 7 + +#define snowyenvironment 0 +#define grassyenvironment 1 +#define desertenvironment 2 +// +// Model Structures +// + +class Terrain +{ +public: + Texture bloodtexture; + Texture bloodtexture2; + Texture shadowtexture; + Texture footprinttexture; + Texture bodyprinttexture; + Texture breaktexture; + Texture terraintexture; + short size; + + int patchobjectnum[subdivision][subdivision]; + int patchobjects[subdivision][subdivision][300]; + + float scale; + int type; + float heightmap[max_terrain_size + 1][max_terrain_size + 1]; + XYZ normals[max_terrain_size][max_terrain_size]; + XYZ facenormals[max_terrain_size][max_terrain_size]; + XYZ triangles[(max_terrain_size - 1) * (max_terrain_size - 1) * 2][3]; + float colors[max_terrain_size][max_terrain_size][4]; + float opacityother[max_terrain_size][max_terrain_size]; + float texoffsetx[max_terrain_size][max_terrain_size]; + float texoffsety[max_terrain_size][max_terrain_size]; + int numtris[subdivision][subdivision]; + int textureness[subdivision][subdivision]; + + GLfloat vArray[(max_patch_elements)*subdivision*subdivision]; + + bool visible[subdivision][subdivision]; + float avgypatch[subdivision][subdivision]; + float maxypatch[subdivision][subdivision]; + float minypatch[subdivision][subdivision]; + float heightypatch[subdivision][subdivision]; + + int patch_elements; + + float decaltexcoords[max_decals][3][2]; + XYZ decalvertex[max_decals][3]; + int decaltype[max_decals]; + float decalopacity[max_decals]; + float decalrotation[max_decals]; + float decalalivetime[max_decals]; + float decalbrightness[max_decals]; + XYZ decalposition[max_decals]; + int numdecals; + + void AddObject(XYZ where, float radius, int id); + void DeleteDecal(int which); + void MakeDecal(int type, XYZ where, float size, float opacity, float rotation); + void MakeDecalLock(int type, XYZ where, int whichx, int whichy, float size, float opacity, float rotation); + int lineTerrain(XYZ p1, XYZ p2, XYZ *p); + float getHeight(float pointx, float pointz); + float getOpacity(float pointx, float pointz); + XYZ getLighting(float pointx, float pointz); + XYZ getNormal(float pointx, float pointz); + void UpdateVertexArray(int whichx, int whichy); + void UpdateTransparency(int whichx, int whichy); + void UpdateTransparencyother(int whichx, int whichy); + void UpdateTransparencyotherother(int whichx, int whichy); + bool load(const std::string& fileName); + void CalculateNormals(); + void drawdecals(); + void draw(int layer); + void drawpatch(int whichx, int whichy, float opacity); + void drawpatchother(int whichx, int whichy, float opacity); + void drawpatchotherother(int whichx, int whichy, float opacity); + void DoShadows(); + + Terrain(); + ~Terrain(); +}; + +#endif diff --git a/Source/Game.cpp b/Source/Game.cpp index e740aa6..76455fb 100644 --- a/Source/Game.cpp +++ b/Source/Game.cpp @@ -18,11 +18,12 @@ You should have received a copy of the GNU General Public License along with Lugaru. If not, see . */ -#include "SDL_thread.h" -#include "Game.h" -#include "Audio/openal_wrapper.h" -#include "Level/Dialog.h" +#include "Game.hpp" +#include "Audio/openal_wrapper.hpp" +#include "Level/Dialog.hpp" + +#include extern int mainmenu; diff --git a/Source/Game.h b/Source/Game.h deleted file mode 100644 index 176d245..0000000 --- a/Source/Game.h +++ /dev/null @@ -1,228 +0,0 @@ -/* -Copyright (C) 2003, 2010 - Wolfire Games -Copyright (C) 2010-2016 - Lugaru contributors (see AUTHORS file) - -This file is part of Lugaru. - -Lugaru is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2 of the License, or -(at your option) any later version. - -Lugaru is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with Lugaru. If not, see . -*/ - -#ifndef _GAME_H_ -#define _GAME_H_ - -#include "SDL.h" - -#include "Animation/Skeleton.h" -#include "Audio/Sounds.h" -#include "Environment/Lights.h" -#include "Environment/Skybox.h" -#include "Environment/Terrain.h" -#include "Graphic/gamegl.h" -#include "Graphic/Models.h" -#include "Graphic/Sprite.h" -#include "Graphic/Stereo.h" -#include "Graphic/Text.h" -#include "Graphic/Texture.h" -#include "Objects/Objects.h" -#include "Objects/Person.h" -#include "Objects/Weapons.h" -#include "Thirdparty/optionparser.h" -#include "User/Account.h" -#include "Utils/binio.h" -#include "Utils/ImageIO.h" - -#include - -#define NB_CAMPAIGN_MENU_ITEM 7 - -namespace Game -{ -extern Texture terraintexture; -extern Texture terraintexture2; -extern Texture loadscreentexture; -extern Texture Maparrowtexture; -extern Texture Mapboxtexture; -extern Texture Mapcircletexture; -extern Texture cursortexture; -extern GLuint screentexture; -extern GLuint screentexture2; -extern Texture Mainmenuitems[10]; - -extern int selected; -extern int keyselect; - -extern int newdetail; -extern int newscreenwidth; -extern int newscreenheight; - -extern bool gameon; -extern float deltah, deltav; -extern int mousecoordh, mousecoordv; -extern int oldmousecoordh, oldmousecoordv; -extern float yaw, pitch; -extern SkyBox *skybox; -extern bool cameramode; -extern bool firstload; - -extern float leveltime; -extern float wonleveltime; -extern float loadtime; - -extern Model hawk; -extern XYZ hawkcoords; -extern XYZ realhawkcoords; -extern Texture hawktexture; -extern float hawkyaw; -extern float hawkcalldelay; - -extern Model eye; -extern Model iris; -extern Model cornea; - -extern bool stealthloading; -extern int loading; - -extern int musictype; - -extern XYZ mapcenter; -extern float mapradius; - -extern Text *text; -extern float fps; - -extern bool editorenabled; -extern int editortype; -extern float editorsize; -extern float editoryaw; -extern float editorpitch; - -extern int tryquit; - -extern XYZ pathpoint[30]; -extern int numpathpoints; -extern int numpathpointconnect[30]; -extern int pathpointconnect[30][30]; -extern int pathpointselected; - -extern int endgame; -extern bool scoreadded; -extern int numchallengelevels; - -extern bool console; -extern std::string consoletext[15]; -extern std::string displaytext[15]; -extern float displaytime[15]; -extern float displayblinkdelay; -extern bool displayblink; -extern unsigned displayselected; -extern float consoleblinkdelay; -extern bool consoleblink; -extern unsigned consoleselected; - -extern int oldenvironment; -extern int targetlevel; -extern float changedelay; - -extern bool waiting; - -extern unsigned short crouchkey, jumpkey, forwardkey, backkey, leftkey, rightkey, drawkey, throwkey, attackkey; -extern unsigned short consolekey; - -void newGame(); -void deleteGame(); - -void InitGame(); -void LoadStuff(); -void LoadScreenTexture(); -void LoadingScreen(); -int DrawGLScene(StereoSide side); -void playdialoguescenesound(); -int findClosestPlayer(); -void Loadlevel(int which); -void Loadlevel(const std::string& name); -void Tick(); -void TickOnce(); -void TickOnceAfter(); -void SetUpLighting(); -GLvoid ReSizeGLScene(float fov, float near); -int checkcollide(XYZ startpoint, XYZ endpoint); -int checkcollide(XYZ startpoint, XYZ endpoint, int what); - -void fireSound(int sound = fireendsound); - -void inputText(std::string& str, unsigned* charselected); -void flash(float amount = 1, int delay = 1); -} - -#ifndef __forceinline -# ifdef __GNUC__ -# define __forceinline inline __attribute__((always_inline)) -# endif -#endif - -static __forceinline void swap_gl_buffers(void) -{ - extern SDL_Window *sdlwindow; - SDL_GL_SwapWindow(sdlwindow); - - // try to limit this to 60fps, even if vsync fails. - Uint32 now; - static Uint32 frameticks = 0; - const Uint32 endticks = (frameticks + 16); - while ((now = SDL_GetTicks()) < endticks) { /* spin. */ } - frameticks = now; -} - -extern "C" { - void UndefinedSymbolToExposeStubbedCode(void); -} -//#define STUBBED(x) UndefinedSymbolToExposeStubbedCode(); -#define STUBBED(x) { static bool seen = false; if (!seen) { seen = true; fprintf(stderr, "STUBBED: %s at %s:%d\n", x, __FILE__, __LINE__); } } -//#define STUBBED(x) - -enum maptypes { - mapkilleveryone, mapgosomewhere, - mapkillsomeone, mapkillmost // These two are unused -}; - -enum pathtypes {wpkeepwalking, wppause}; - -extern const char *pathtypenames[2]; - -enum editortypes {typeactive, typesitting, typesittingwall, typesleeping, - typedead1, typedead2, typedead3, typedead4 - }; - -extern const char *editortypenames[8]; - -extern const char *rabbitskin[10]; - -extern const char *wolfskin[3]; - -extern const char **creatureskin[2]; - -SDL_bool sdlEventProc(const SDL_Event &e); - - - -enum optionIndex { UNKNOWN, HELP, FULLSCREEN, NOMOUSEGRAB, SOUND, OPENALINFO, SHOWRESOLUTIONS, DEVTOOLS }; -/* Number of options + 1 */ -const int commandLineOptionsNumber = 9; - -extern const option::Descriptor usage[13]; - -extern option::Option commandLineOptions[commandLineOptionsNumber]; -extern option::Option* commandLineOptionsBuffer; - -#endif diff --git a/Source/Game.hpp b/Source/Game.hpp new file mode 100644 index 0000000..596ade4 --- /dev/null +++ b/Source/Game.hpp @@ -0,0 +1,227 @@ +/* +Copyright (C) 2003, 2010 - Wolfire Games +Copyright (C) 2010-2016 - Lugaru contributors (see AUTHORS file) + +This file is part of Lugaru. + +Lugaru is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +Lugaru is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with Lugaru. If not, see . +*/ + +#ifndef _GAME_HPP_ +#define _GAME_HPP_ + +#include "Animation/Skeleton.hpp" +#include "Audio/Sounds.hpp" +#include "Environment/Lights.hpp" +#include "Environment/Skybox.hpp" +#include "Environment/Terrain.hpp" +#include "Graphic/gamegl.hpp" +#include "Graphic/Models.hpp" +#include "Graphic/Sprite.hpp" +#include "Graphic/Stereo.hpp" +#include "Graphic/Text.hpp" +#include "Graphic/Texture.hpp" +#include "Objects/Objects.hpp" +#include "Objects/Person.hpp" +#include "Objects/Weapons.hpp" +#include "Thirdparty/optionparser.h" +#include "User/Account.hpp" +#include "Utils/binio.h" +#include "Utils/ImageIO.hpp" + +#include +#include + +#define NB_CAMPAIGN_MENU_ITEM 7 + +namespace Game +{ +extern Texture terraintexture; +extern Texture terraintexture2; +extern Texture loadscreentexture; +extern Texture Maparrowtexture; +extern Texture Mapboxtexture; +extern Texture Mapcircletexture; +extern Texture cursortexture; +extern GLuint screentexture; +extern GLuint screentexture2; +extern Texture Mainmenuitems[10]; + +extern int selected; +extern int keyselect; + +extern int newdetail; +extern int newscreenwidth; +extern int newscreenheight; + +extern bool gameon; +extern float deltah, deltav; +extern int mousecoordh, mousecoordv; +extern int oldmousecoordh, oldmousecoordv; +extern float yaw, pitch; +extern SkyBox *skybox; +extern bool cameramode; +extern bool firstload; + +extern float leveltime; +extern float wonleveltime; +extern float loadtime; + +extern Model hawk; +extern XYZ hawkcoords; +extern XYZ realhawkcoords; +extern Texture hawktexture; +extern float hawkyaw; +extern float hawkcalldelay; + +extern Model eye; +extern Model iris; +extern Model cornea; + +extern bool stealthloading; +extern int loading; + +extern int musictype; + +extern XYZ mapcenter; +extern float mapradius; + +extern Text *text; +extern float fps; + +extern bool editorenabled; +extern int editortype; +extern float editorsize; +extern float editoryaw; +extern float editorpitch; + +extern int tryquit; + +extern XYZ pathpoint[30]; +extern int numpathpoints; +extern int numpathpointconnect[30]; +extern int pathpointconnect[30][30]; +extern int pathpointselected; + +extern int endgame; +extern bool scoreadded; +extern int numchallengelevels; + +extern bool console; +extern std::string consoletext[15]; +extern std::string displaytext[15]; +extern float displaytime[15]; +extern float displayblinkdelay; +extern bool displayblink; +extern unsigned displayselected; +extern float consoleblinkdelay; +extern bool consoleblink; +extern unsigned consoleselected; + +extern int oldenvironment; +extern int targetlevel; +extern float changedelay; + +extern bool waiting; + +extern unsigned short crouchkey, jumpkey, forwardkey, backkey, leftkey, rightkey, drawkey, throwkey, attackkey; +extern unsigned short consolekey; + +void newGame(); +void deleteGame(); + +void InitGame(); +void LoadStuff(); +void LoadScreenTexture(); +void LoadingScreen(); +int DrawGLScene(StereoSide side); +void playdialoguescenesound(); +int findClosestPlayer(); +void Loadlevel(int which); +void Loadlevel(const std::string& name); +void Tick(); +void TickOnce(); +void TickOnceAfter(); +void SetUpLighting(); +GLvoid ReSizeGLScene(float fov, float near); +int checkcollide(XYZ startpoint, XYZ endpoint); +int checkcollide(XYZ startpoint, XYZ endpoint, int what); + +void fireSound(int sound = fireendsound); + +void inputText(std::string& str, unsigned* charselected); +void flash(float amount = 1, int delay = 1); +} + +#ifndef __forceinline +# ifdef __GNUC__ +# define __forceinline inline __attribute__((always_inline)) +# endif +#endif + +static __forceinline void swap_gl_buffers(void) +{ + extern SDL_Window *sdlwindow; + SDL_GL_SwapWindow(sdlwindow); + + // try to limit this to 60fps, even if vsync fails. + Uint32 now; + static Uint32 frameticks = 0; + const Uint32 endticks = (frameticks + 16); + while ((now = SDL_GetTicks()) < endticks) { /* spin. */ } + frameticks = now; +} + +extern "C" { + void UndefinedSymbolToExposeStubbedCode(void); +} +//#define STUBBED(x) UndefinedSymbolToExposeStubbedCode(); +#define STUBBED(x) { static bool seen = false; if (!seen) { seen = true; fprintf(stderr, "STUBBED: %s at %s:%d\n", x, __FILE__, __LINE__); } } +//#define STUBBED(x) + +enum maptypes { + mapkilleveryone, mapgosomewhere, + mapkillsomeone, mapkillmost // These two are unused +}; + +enum pathtypes {wpkeepwalking, wppause}; + +extern const char *pathtypenames[2]; + +enum editortypes {typeactive, typesitting, typesittingwall, typesleeping, + typedead1, typedead2, typedead3, typedead4 + }; + +extern const char *editortypenames[8]; + +extern const char *rabbitskin[10]; + +extern const char *wolfskin[3]; + +extern const char **creatureskin[2]; + +SDL_bool sdlEventProc(const SDL_Event &e); + + + +enum optionIndex { UNKNOWN, HELP, FULLSCREEN, NOMOUSEGRAB, SOUND, OPENALINFO, SHOWRESOLUTIONS, DEVTOOLS }; +/* Number of options + 1 */ +const int commandLineOptionsNumber = 9; + +extern const option::Descriptor usage[13]; + +extern option::Option commandLineOptions[commandLineOptionsNumber]; +extern option::Option* commandLineOptionsBuffer; + +#endif diff --git a/Source/GameDraw.cpp b/Source/GameDraw.cpp index d46b9b6..fcee8b5 100644 --- a/Source/GameDraw.cpp +++ b/Source/GameDraw.cpp @@ -18,13 +18,14 @@ You should have received a copy of the GNU General Public License along with Lugaru. If not, see . */ -#include "Game.h" -#include "Audio/openal_wrapper.h" -#include "Level/Awards.h" -#include "Level/Dialog.h" -#include "Level/Hotspot.h" -#include "Menu/Menu.h" -#include "Utils/Input.h" +#include "Game.hpp" + +#include "Audio/openal_wrapper.hpp" +#include "Level/Awards.hpp" +#include "Level/Dialog.hpp" +#include "Level/Hotspot.hpp" +#include "Menu/Menu.hpp" +#include "Utils/Input.hpp" extern XYZ viewer; extern int environment; diff --git a/Source/GameInitDispose.cpp b/Source/GameInitDispose.cpp index 036f80f..d950c2e 100644 --- a/Source/GameInitDispose.cpp +++ b/Source/GameInitDispose.cpp @@ -18,12 +18,13 @@ You should have received a copy of the GNU General Public License along with Lugaru. If not, see . */ -#include "Game.h" -#include "Animation/Animation.h" -#include "Audio/openal_wrapper.h" -#include "Graphic/Texture.h" -#include "Menu/Menu.h" -#include "Utils/Folders.h" +#include "Game.hpp" + +#include "Animation/Animation.hpp" +#include "Audio/openal_wrapper.hpp" +#include "Graphic/Texture.hpp" +#include "Menu/Menu.hpp" +#include "Utils/Folders.hpp" extern float screenwidth, screenheight; extern float viewdistance; @@ -650,7 +651,7 @@ void Game::LoadScreenTexture() glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 0, 0, kTextureSize, kTextureSize, 0); } -//TODO: move LoadStuff() closer to GameTick.cpp to get rid of various vars shared in Game.h +//TODO: move LoadStuff() closer to GameTick.cpp to get rid of various vars shared in Game.hpp void Game::LoadStuff() { static float temptexdetail; diff --git a/Source/GameTick.cpp b/Source/GameTick.cpp index 37a29f5..ed61f24 100644 --- a/Source/GameTick.cpp +++ b/Source/GameTick.cpp @@ -21,6 +21,20 @@ along with Lugaru. If not, see . // Enable full math definitions #define _USE_MATH_DEFINES +#include "Game.hpp" + +#include "Animation/Animation.hpp" +#include "Audio/openal_wrapper.hpp" +#include "Devtools/ConsoleCmds.hpp" +#include "Level/Awards.hpp" +#include "Level/Campaign.hpp" +#include "Level/Dialog.hpp" +#include "Level/Hotspot.hpp" +#include "Menu/Menu.hpp" +#include "User/Settings.hpp" +#include "Utils/Folders.hpp" +#include "Utils/Input.hpp" + #if PLATFORM_UNIX #include #include @@ -29,25 +43,11 @@ along with Lugaru. If not, see . #include #endif - -#include -#include +#include #include +#include #include -#include "Game.h" -#include "Animation/Animation.h" -#include "Audio/openal_wrapper.h" -#include "Devtools/ConsoleCmds.h" -#include "Level/Awards.h" -#include "Level/Campaign.h" -#include "Level/Dialog.h" -#include "Level/Hotspot.h" -#include "Menu/Menu.h" -#include "User/Settings.h" -#include "Utils/Folders.h" -#include "Utils/Input.h" - -#include +#include #include using namespace std; diff --git a/Source/Globals.cpp b/Source/Globals.cpp index 66c6c9b..485b607 100644 --- a/Source/Globals.cpp +++ b/Source/Globals.cpp @@ -18,14 +18,13 @@ You should have received a copy of the GNU General Public License along with Lugaru. If not, see . */ -#include "SDL.h" +#include "Graphic/Stereo.hpp" +#include "Math/Quaternions.hpp" +#include "Objects/Weapons.hpp" +#include #include -#include "Graphic/Stereo.h" -#include "Math/Quaternions.h" -#include "Objects/Weapons.h" - bool visibleloading = 0; float volume = 0; diff --git a/Source/Graphic/Models.cpp b/Source/Graphic/Models.cpp index a9833d0..649bcde 100644 --- a/Source/Graphic/Models.cpp +++ b/Source/Graphic/Models.cpp @@ -18,9 +18,10 @@ You should have received a copy of the GNU General Public License along with Lugaru. If not, see . */ -#include "Game.h" -#include "Graphic/Models.h" -#include "Utils/Folders.h" +#include "Graphic/Models.hpp" + +#include "Game.hpp" +#include "Utils/Folders.hpp" extern float multiplier; extern float viewdistance; diff --git a/Source/Graphic/Models.h b/Source/Graphic/Models.h deleted file mode 100644 index e14ebe6..0000000 --- a/Source/Graphic/Models.h +++ /dev/null @@ -1,151 +0,0 @@ -/* -Copyright (C) 2003, 2010 - Wolfire Games -Copyright (C) 2010-2016 - Lugaru contributors (see AUTHORS file) - -This file is part of Lugaru. - -Lugaru is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2 of the License, or -(at your option) any later version. - -Lugaru is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with Lugaru. If not, see . -*/ - -#ifndef _MODELS_H_ -#define _MODELS_H_ - -/**> Model Loading <**/ -// -// Model Maximums -// -#include "Graphic/gamegl.h" -#include -#include -#include -#include - -#include "Environment/Terrain.h" -#include "Graphic/Texture.h" -#include "Math/Quaternions.h" -#include "Utils/binio.h" - -// -// Textures List -// -typedef struct { - long xsz, ysz; - GLubyte *txt; -} ModelTexture; - -// -// Model Structures -// - -class TexturedTriangle -{ -public: - short vertex[3]; - float gx[3], gy[3]; -}; - -#define max_model_decals 300 - -#define nothing 0 -#define normaltype 4 -#define notextype 1 -#define rawtype 2 -#define decalstype 3 - -class Model -{ -public: - short vertexNum, TriangleNum; - bool hastexture; - - int type, oldtype; - - int* possible; - int* owner; - XYZ* vertex; - XYZ* normals; - XYZ* facenormals; - TexturedTriangle* Triangles; - GLfloat* vArray; - - /*int possible[max_model_vertex]; - int owner[max_textured_triangle]; - XYZ vertex[max_model_vertex]; - XYZ normals[max_model_vertex]; - XYZ facenormals[max_textured_triangle]; - TexturedTriangle Triangles[max_textured_triangle]; - GLfloat vArray[max_textured_triangle*24];*/ - - Texture textureptr; - ModelTexture modelTexture; - int numpossible; - bool color; - - XYZ boundingspherecenter; - float boundingsphereradius; - - float*** decaltexcoords; - XYZ** decalvertex; - int* decaltype; - float* decalopacity; - float* decalrotation; - float* decalalivetime; - XYZ* decalposition; - - /*float decaltexcoords[max_model_decals][3][2]; - XYZ decalvertex[max_model_decals][3]; - int decaltype[max_model_decals]; - float decalopacity[max_model_decals]; - float decalrotation[max_model_decals]; - float decalalivetime[max_model_decals]; - XYZ decalposition[max_model_decals];*/ - - int numdecals; - - bool flat; - - void DeleteDecal(int which); - void MakeDecal(int atype, XYZ *where, float *size, float *opacity, float *rotation); - void MakeDecal(int atype, XYZ where, float size, float opacity, float rotation); - void drawdecals(Texture shadowtexture, Texture bloodtexture, Texture bloodtexture2, Texture breaktexture); - int SphereCheck(XYZ *p1, float radius, XYZ *p, XYZ *move, float *rotate); - int SphereCheckPossible(XYZ *p1, float radius, XYZ *move, float *rotate); - int LineCheck(XYZ *p1, XYZ *p2, XYZ *p, XYZ *move, float *rotate); - int LineCheckPossible(XYZ *p1, XYZ *p2, XYZ *p, XYZ *move, float *rotate); - int LineCheckSlidePossible(XYZ *p1, XYZ *p2, XYZ *p, XYZ *move, float *rotate); - void UpdateVertexArray(); - void UpdateVertexArrayNoTex(); - void UpdateVertexArrayNoTexNoNorm(); - bool loadnotex(const std::string& filename); - bool loadraw(const std::string& filename); - bool load(const std::string& filename, bool texture); - bool loaddecal(const std::string& filename, bool texture); - void Scale(float xscale, float yscale, float zscale); - void FlipTexCoords(); - void UniformTexCoords(); - void ScaleTexCoords(float howmuch); - void ScaleNormals(float xscale, float yscale, float zscale); - void Translate(float xtrans, float ytrans, float ztrans); - void CalculateNormals(bool facenormalise); - void draw(); - void drawdifftex(GLuint texture); - void drawdifftex(Texture texture); - void drawimmediate(); - void Rotate(float xang, float yang, float zang); - ~Model(); - void deallocate(); - Model(); -}; - -#endif diff --git a/Source/Graphic/Models.hpp b/Source/Graphic/Models.hpp new file mode 100644 index 0000000..621a9af --- /dev/null +++ b/Source/Graphic/Models.hpp @@ -0,0 +1,147 @@ +/* +Copyright (C) 2003, 2010 - Wolfire Games +Copyright (C) 2010-2016 - Lugaru contributors (see AUTHORS file) + +This file is part of Lugaru. + +Lugaru is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +Lugaru is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with Lugaru. If not, see . +*/ + +#ifndef _MODELS_HPP_ +#define _MODELS_HPP_ + +#include "Environment/Terrain.hpp" +#include "Graphic/gamegl.hpp" +#include "Graphic/Texture.hpp" +#include "Math/Quaternions.hpp" +#include "Utils/binio.h" + +#include +#include +#include +#include + +// +// Textures List +// +typedef struct { + long xsz, ysz; + GLubyte *txt; +} ModelTexture; + +// +// Model Structures +// + +class TexturedTriangle +{ +public: + short vertex[3]; + float gx[3], gy[3]; +}; + +#define max_model_decals 300 + +#define nothing 0 +#define normaltype 4 +#define notextype 1 +#define rawtype 2 +#define decalstype 3 + +class Model +{ +public: + short vertexNum, TriangleNum; + bool hastexture; + + int type, oldtype; + + int* possible; + int* owner; + XYZ* vertex; + XYZ* normals; + XYZ* facenormals; + TexturedTriangle* Triangles; + GLfloat* vArray; + + /*int possible[max_model_vertex]; + int owner[max_textured_triangle]; + XYZ vertex[max_model_vertex]; + XYZ normals[max_model_vertex]; + XYZ facenormals[max_textured_triangle]; + TexturedTriangle Triangles[max_textured_triangle]; + GLfloat vArray[max_textured_triangle*24];*/ + + Texture textureptr; + ModelTexture modelTexture; + int numpossible; + bool color; + + XYZ boundingspherecenter; + float boundingsphereradius; + + float*** decaltexcoords; + XYZ** decalvertex; + int* decaltype; + float* decalopacity; + float* decalrotation; + float* decalalivetime; + XYZ* decalposition; + + /*float decaltexcoords[max_model_decals][3][2]; + XYZ decalvertex[max_model_decals][3]; + int decaltype[max_model_decals]; + float decalopacity[max_model_decals]; + float decalrotation[max_model_decals]; + float decalalivetime[max_model_decals]; + XYZ decalposition[max_model_decals];*/ + + int numdecals; + + bool flat; + + void DeleteDecal(int which); + void MakeDecal(int atype, XYZ *where, float *size, float *opacity, float *rotation); + void MakeDecal(int atype, XYZ where, float size, float opacity, float rotation); + void drawdecals(Texture shadowtexture, Texture bloodtexture, Texture bloodtexture2, Texture breaktexture); + int SphereCheck(XYZ *p1, float radius, XYZ *p, XYZ *move, float *rotate); + int SphereCheckPossible(XYZ *p1, float radius, XYZ *move, float *rotate); + int LineCheck(XYZ *p1, XYZ *p2, XYZ *p, XYZ *move, float *rotate); + int LineCheckPossible(XYZ *p1, XYZ *p2, XYZ *p, XYZ *move, float *rotate); + int LineCheckSlidePossible(XYZ *p1, XYZ *p2, XYZ *p, XYZ *move, float *rotate); + void UpdateVertexArray(); + void UpdateVertexArrayNoTex(); + void UpdateVertexArrayNoTexNoNorm(); + bool loadnotex(const std::string& filename); + bool loadraw(const std::string& filename); + bool load(const std::string& filename, bool texture); + bool loaddecal(const std::string& filename, bool texture); + void Scale(float xscale, float yscale, float zscale); + void FlipTexCoords(); + void UniformTexCoords(); + void ScaleTexCoords(float howmuch); + void ScaleNormals(float xscale, float yscale, float zscale); + void Translate(float xtrans, float ytrans, float ztrans); + void CalculateNormals(bool facenormalise); + void draw(); + void drawdifftex(GLuint texture); + void drawdifftex(Texture texture); + void drawimmediate(); + void Rotate(float xang, float yang, float zang); + ~Model(); + void deallocate(); + Model(); +}; + +#endif diff --git a/Source/Graphic/Sprite.cpp b/Source/Graphic/Sprite.cpp index 4276ce5..8cd5c7f 100644 --- a/Source/Graphic/Sprite.cpp +++ b/Source/Graphic/Sprite.cpp @@ -18,9 +18,10 @@ You should have received a copy of the GNU General Public License along with Lugaru. If not, see . */ -#include "Game.h" -#include "Graphic/Sprite.h" -#include "Objects/Person.h" +#include "Graphic/Sprite.hpp" + +#include "Game.hpp" +#include "Objects/Person.hpp" extern XYZ viewer; extern float viewdistance; diff --git a/Source/Graphic/Sprite.h b/Source/Graphic/Sprite.h deleted file mode 100644 index bed8439..0000000 --- a/Source/Graphic/Sprite.h +++ /dev/null @@ -1,111 +0,0 @@ -/* -Copyright (C) 2003, 2010 - Wolfire Games -Copyright (C) 2010-2016 - Lugaru contributors (see AUTHORS file) - -This file is part of Lugaru. - -Lugaru is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2 of the License, or -(at your option) any later version. - -Lugaru is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with Lugaru. If not, see . -*/ - -#ifndef _SPRITE_H_ -#define _SPRITE_H_ - -#include "Environment/Lights.h" -#include "Environment/Terrain.h" -#include "Graphic/gamegl.h" -#include "Graphic/Texture.h" -#include "Math/Frustum.h" -#include "Math/Quaternions.h" -#include "Math/Quaternions.h" -#include "Objects/Objects.h" -#include "Utils/ImageIO.h" - -#include - -#define max_sprites 20000 - -enum { - cloudsprite = 0, - bloodsprite, - flamesprite, - smoketype, - weaponflamesprite, - cloudimpactsprite, - snowsprite, - weaponshinesprite, - bloodflamesprite, - breathsprite, - splintersprite, - spritenumber -}; - -class Sprite -{ -private: - XYZ oldposition; - XYZ position; - XYZ velocity; - float size; - float initialsize; - int type; - int special; - float color[3]; - float opacity; - float rotation; - float alivetime; - float speed; - float rotatespeed; - - static float checkdelay; - - static vector sprites; - -public: - static void DeleteSprite(int which); - static void MakeSprite(int atype, XYZ where, XYZ avelocity, float red, float green, float blue, float asize, float aopacity); - static void Draw(); - static void deleteSprites() { - sprites.clear(); - } - static void setLastSpriteSpecial(int s) { - sprites.back()->special = s; - } - static void setLastSpriteSpeed(int s) { - sprites.back()->speed = s; - } - static void setLastSpriteAlivetime(float al) { - sprites.back()->alivetime = al; - } - static void clearTextures(); - - static Texture cloudtexture; - static Texture bloodtexture; - static Texture flametexture; - static Texture smoketexture; - - static Texture cloudimpacttexture; - static Texture snowflaketexture; - static Texture shinetexture; - static Texture bloodflametexture; - - static Texture splintertexture; - - static Texture leaftexture; - static Texture toothtexture; - - Sprite(); - ~Sprite(); -}; - -#endif diff --git a/Source/Graphic/Sprite.hpp b/Source/Graphic/Sprite.hpp new file mode 100644 index 0000000..01e68a3 --- /dev/null +++ b/Source/Graphic/Sprite.hpp @@ -0,0 +1,110 @@ +/* +Copyright (C) 2003, 2010 - Wolfire Games +Copyright (C) 2010-2016 - Lugaru contributors (see AUTHORS file) + +This file is part of Lugaru. + +Lugaru is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +Lugaru is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with Lugaru. If not, see . +*/ + +#ifndef _SPRITE_HPP_ +#define _SPRITE_HPP_ + +#include "Environment/Lights.hpp" +#include "Environment/Terrain.hpp" +#include "Graphic/gamegl.hpp" +#include "Graphic/Texture.hpp" +#include "Math/Frustum.hpp" +#include "Math/Quaternions.hpp" +#include "Objects/Objects.hpp" +#include "Utils/ImageIO.hpp" + +#include + +#define max_sprites 20000 + +enum { + cloudsprite = 0, + bloodsprite, + flamesprite, + smoketype, + weaponflamesprite, + cloudimpactsprite, + snowsprite, + weaponshinesprite, + bloodflamesprite, + breathsprite, + splintersprite, + spritenumber +}; + +class Sprite +{ +private: + XYZ oldposition; + XYZ position; + XYZ velocity; + float size; + float initialsize; + int type; + int special; + float color[3]; + float opacity; + float rotation; + float alivetime; + float speed; + float rotatespeed; + + static float checkdelay; + + static vector sprites; + +public: + static void DeleteSprite(int which); + static void MakeSprite(int atype, XYZ where, XYZ avelocity, float red, float green, float blue, float asize, float aopacity); + static void Draw(); + static void deleteSprites() { + sprites.clear(); + } + static void setLastSpriteSpecial(int s) { + sprites.back()->special = s; + } + static void setLastSpriteSpeed(int s) { + sprites.back()->speed = s; + } + static void setLastSpriteAlivetime(float al) { + sprites.back()->alivetime = al; + } + static void clearTextures(); + + static Texture cloudtexture; + static Texture bloodtexture; + static Texture flametexture; + static Texture smoketexture; + + static Texture cloudimpacttexture; + static Texture snowflaketexture; + static Texture shinetexture; + static Texture bloodflametexture; + + static Texture splintertexture; + + static Texture leaftexture; + static Texture toothtexture; + + Sprite(); + ~Sprite(); +}; + +#endif diff --git a/Source/Graphic/Stereo.cpp b/Source/Graphic/Stereo.cpp index efb300b..66938e2 100644 --- a/Source/Graphic/Stereo.cpp +++ b/Source/Graphic/Stereo.cpp @@ -18,9 +18,9 @@ You should have received a copy of the GNU General Public License along with Lugaru. If not, see . */ -#include "Game.h" -#include "Graphic/Stereo.h" +#include "Graphic/Stereo.hpp" +#include "Game.hpp" extern int kContextWidth; extern int kContextHeight; diff --git a/Source/Graphic/Stereo.h b/Source/Graphic/Stereo.h deleted file mode 100644 index 8e70e5e..0000000 --- a/Source/Graphic/Stereo.h +++ /dev/null @@ -1,52 +0,0 @@ -/* -Copyright (C) 2003, 2010 - Wolfire Games -Copyright (C) 2010-2016 - Lugaru contributors (see AUTHORS file) - -This file is part of Lugaru. - -Lugaru is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2 of the License, or -(at your option) any later version. - -Lugaru is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with Lugaru. If not, see . -*/ - -#ifndef STEREO_H_ -#define STEREO_H_ - -enum StereoMode { - stereoNone, - stereoAnaglyph, /* red/cyan */ - stereoHorizontalInterlaced, /* some 3D monitors */ - stereoVerticalInterlaced, - stereoHorizontalSplit, /* cross-eyed view */ - stereoVerticalSplit, - stereoOpenGL, /* Whatever OpenGL does, if supported */ - stereoCount /* must be last element */ -}; - - -enum StereoSide { - // Code multiplies by StereoSide to calculate camera offsets - stereoLeft = -1, - stereoCenter = 0, - stereoRight = 1 -}; - -extern StereoMode stereomode; -extern StereoMode newstereomode; -extern float stereoseparation; -extern bool stereoreverse; - -bool CanInitStereo(StereoMode mode); -void InitStereo(StereoMode mode); -const std::string StereoModeName(StereoMode mode); - -#endif diff --git a/Source/Graphic/Stereo.hpp b/Source/Graphic/Stereo.hpp new file mode 100644 index 0000000..e93d113 --- /dev/null +++ b/Source/Graphic/Stereo.hpp @@ -0,0 +1,54 @@ +/* +Copyright (C) 2003, 2010 - Wolfire Games +Copyright (C) 2010-2016 - Lugaru contributors (see AUTHORS file) + +This file is part of Lugaru. + +Lugaru is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +Lugaru is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with Lugaru. If not, see . +*/ + +#ifndef _STEREO_HPP_ +#define _STEREO_HPP_ + +#include + +enum StereoMode { + stereoNone, + stereoAnaglyph, /* red/cyan */ + stereoHorizontalInterlaced, /* some 3D monitors */ + stereoVerticalInterlaced, + stereoHorizontalSplit, /* cross-eyed view */ + stereoVerticalSplit, + stereoOpenGL, /* Whatever OpenGL does, if supported */ + stereoCount /* must be last element */ +}; + + +enum StereoSide { + // Code multiplies by StereoSide to calculate camera offsets + stereoLeft = -1, + stereoCenter = 0, + stereoRight = 1 +}; + +extern StereoMode stereomode; +extern StereoMode newstereomode; +extern float stereoseparation; +extern bool stereoreverse; + +bool CanInitStereo(StereoMode mode); +void InitStereo(StereoMode mode); +const std::string StereoModeName(StereoMode mode); + +#endif diff --git a/Source/Graphic/Text.cpp b/Source/Graphic/Text.cpp index 31bbe9f..47d8c3e 100644 --- a/Source/Graphic/Text.cpp +++ b/Source/Graphic/Text.cpp @@ -18,9 +18,9 @@ You should have received a copy of the GNU General Public License along with Lugaru. If not, see . */ -/**> HEADER FILES <**/ -#include "Graphic/Text.h" -#include "Game.h" +#include "Graphic/Text.hpp" + +#include "Game.hpp" void Text::LoadFontTexture(const std::string& fileName) { diff --git a/Source/Graphic/Text.h b/Source/Graphic/Text.h deleted file mode 100644 index b5cc8a1..0000000 --- a/Source/Graphic/Text.h +++ /dev/null @@ -1,52 +0,0 @@ -/* -Copyright (C) 2003, 2010 - Wolfire Games -Copyright (C) 2010-2016 - Lugaru contributors (see AUTHORS file) - -This file is part of Lugaru. - -Lugaru is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2 of the License, or -(at your option) any later version. - -Lugaru is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with Lugaru. If not, see . -*/ - -#ifndef _TEXT_H_ -#define _TEXT_H_ - -/**> HEADER FILES <**/ -#include "Graphic/gamegl.h" -#include "Graphic/Texture.h" -#include "Math/Quaternions.h" -#include "Utils/ImageIO.h" - -class Text -{ -public: - Texture FontTexture; - GLuint base; - - void LoadFontTexture(const std::string& fileName); - void BuildFont(); - void glPrint(float x, float y, const char *string, int set, float size, float width, float height); - void glPrintOutline(float x, float y, const char *string, int set, float size, float width, float height); - void glPrint(float x, float y, const char *string, int set, float size, float width, float height, int start, int end); - void glPrintOutline(float x, float y, const char *string, int set, float size, float width, float height, int start, int end); - void glPrintOutlined(float x, float y, const char *string, int set, float size, float width, float height); - void glPrintOutlined(float r, float g, float b, float x, float y, const char *string, int set, float size, float width, float height); - - Text(); - ~Text(); - -private: - void _glPrint(float x, float y, const char *string, int set, float size, float width, float height, int start, int end, int offset); -}; - -#endif diff --git a/Source/Graphic/Text.hpp b/Source/Graphic/Text.hpp new file mode 100644 index 0000000..d830af4 --- /dev/null +++ b/Source/Graphic/Text.hpp @@ -0,0 +1,51 @@ +/* +Copyright (C) 2003, 2010 - Wolfire Games +Copyright (C) 2010-2016 - Lugaru contributors (see AUTHORS file) + +This file is part of Lugaru. + +Lugaru is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +Lugaru is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with Lugaru. If not, see . +*/ + +#ifndef _TEXT_HPP_ +#define _TEXT_HPP_ + +#include "Graphic/gamegl.hpp" +#include "Graphic/Texture.hpp" +#include "Math/Quaternions.hpp" +#include "Utils/ImageIO.hpp" + +class Text +{ +public: + Texture FontTexture; + GLuint base; + + void LoadFontTexture(const std::string& fileName); + void BuildFont(); + void glPrint(float x, float y, const char *string, int set, float size, float width, float height); + void glPrintOutline(float x, float y, const char *string, int set, float size, float width, float height); + void glPrint(float x, float y, const char *string, int set, float size, float width, float height, int start, int end); + void glPrintOutline(float x, float y, const char *string, int set, float size, float width, float height, int start, int end); + void glPrintOutlined(float x, float y, const char *string, int set, float size, float width, float height); + void glPrintOutlined(float r, float g, float b, float x, float y, const char *string, int set, float size, float width, float height); + + Text(); + ~Text(); + +private: + void _glPrint(float x, float y, const char *string, int set, float size, float width, float height, int start, int end, int offset); +}; + +#endif diff --git a/Source/Graphic/Texture.cpp b/Source/Graphic/Texture.cpp index 3f5211a..e2565e9 100644 --- a/Source/Graphic/Texture.cpp +++ b/Source/Graphic/Texture.cpp @@ -18,10 +18,10 @@ You should have received a copy of the GNU General Public License along with Lugaru. If not, see . */ -#include "Graphic/gamegl.h" -#include "Graphic/Texture.h" -#include "Utils/Folders.h" -#include "Utils/ImageIO.h" +#include "Graphic/Texture.hpp" + +#include "Utils/Folders.hpp" +#include "Utils/ImageIO.hpp" using namespace std; diff --git a/Source/Graphic/Texture.h b/Source/Graphic/Texture.h deleted file mode 100644 index 95547bf..0000000 --- a/Source/Graphic/Texture.h +++ /dev/null @@ -1,63 +0,0 @@ -/* -Copyright (C) 2003, 2010 - Wolfire Games -Copyright (C) 2010-2016 - Lugaru contributors (see AUTHORS file) - -This file is part of Lugaru. - -Lugaru is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2 of the License, or -(at your option) any later version. - -Lugaru is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with Lugaru. If not, see . -*/ - -#ifndef _TEXTURE_H_ -#define _TEXTURE_H_ - -#include -#include -#include -using namespace std; - -class TextureRes -{ -private: - static vector list; - - GLuint id; - string filename; - bool hasMipmap; - bool isSkin; - int skinsize; - GLubyte* data; - int datalen; - - void load(); - -public: - TextureRes(const string& filename, bool hasMipmap); - TextureRes(const string& filename, bool hasMipmap, GLubyte* array, int* skinsize); - ~TextureRes(); - void bind(); -}; - -class Texture -{ -private: - TextureRes* tex; -public: - inline Texture(): tex(NULL) {} - void load(const string& filename, bool hasMipmap); - void load(const string& filename, bool hasMipmap, GLubyte* array, int* skinsizep); - void destroy(); - void bind(); -}; - -#endif diff --git a/Source/Graphic/Texture.hpp b/Source/Graphic/Texture.hpp new file mode 100644 index 0000000..ab51cdb --- /dev/null +++ b/Source/Graphic/Texture.hpp @@ -0,0 +1,66 @@ +/* +Copyright (C) 2003, 2010 - Wolfire Games +Copyright (C) 2010-2016 - Lugaru contributors (see AUTHORS file) + +This file is part of Lugaru. + +Lugaru is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +Lugaru is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with Lugaru. If not, see . +*/ + +#ifndef _TEXTURE_HPP_ +#define _TEXTURE_HPP_ + +#include "Graphic/gamegl.hpp" + +#include +#include +#include + +using namespace std; + +class TextureRes +{ +private: + static vector list; + + GLuint id; + string filename; + bool hasMipmap; + bool isSkin; + int skinsize; + GLubyte* data; + int datalen; + + void load(); + +public: + TextureRes(const string& filename, bool hasMipmap); + TextureRes(const string& filename, bool hasMipmap, GLubyte* array, int* skinsize); + ~TextureRes(); + void bind(); +}; + +class Texture +{ +private: + TextureRes* tex; +public: + inline Texture(): tex(NULL) {} + void load(const string& filename, bool hasMipmap); + void load(const string& filename, bool hasMipmap, GLubyte* array, int* skinsizep); + void destroy(); + void bind(); +}; + +#endif diff --git a/Source/Graphic/gamegl.h b/Source/Graphic/gamegl.h deleted file mode 100644 index 9bee196..0000000 --- a/Source/Graphic/gamegl.h +++ /dev/null @@ -1,53 +0,0 @@ -/* -Copyright (C) 2003, 2010 - Wolfire Games -Copyright (C) 2010-2016 - Lugaru contributors (see AUTHORS file) - -This file is part of Lugaru. - -Lugaru is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2 of the License, or -(at your option) any later version. - -Lugaru is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with Lugaru. If not, see . -*/ - -#ifndef _LUGARU_GL_H_ -#define _LUGARU_GL_H_ - - -#include -#include -#include -#include -#include -#include - -#ifdef WIN32 - #define WIN32_LEAN_AND_MEAN - #define Polygon WinPolygon - #include - #undef Polygon -#endif - -#define GL_GLEXT_PROTOTYPES 1 -#include "GL/gl.h" -#include "GL/glu.h" -#include "GL/glext.h" -#include "MacCompatibility.h" - -using namespace std; - -/* !!! FIXME: until we replace logger better. --ryan. */ -#define LOGFUNC -void LOG(const std::string &fmt, ...); - -#endif - - diff --git a/Source/Graphic/gamegl.hpp b/Source/Graphic/gamegl.hpp new file mode 100644 index 0000000..0b5f693 --- /dev/null +++ b/Source/Graphic/gamegl.hpp @@ -0,0 +1,53 @@ +/* +Copyright (C) 2003, 2010 - Wolfire Games +Copyright (C) 2010-2016 - Lugaru contributors (see AUTHORS file) + +This file is part of Lugaru. + +Lugaru is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +Lugaru is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with Lugaru. If not, see . +*/ + +#ifndef _GAMEGL_HPP_ +#define _GAMEGL_HPP_ + +#include "MacCompatibility.hpp" + +#include +#include +#include +#include +#include +#include + +#ifdef WIN32 + #define WIN32_LEAN_AND_MEAN + #define Polygon WinPolygon + #include + #undef Polygon +#endif + +#define GL_GLEXT_PROTOTYPES 1 +#include +#include +#include + +using namespace std; + +/* !!! FIXME: until we replace logger better. --ryan. */ +#define LOGFUNC +void LOG(const std::string &fmt, ...); + +#endif + + diff --git a/Source/Level/Awards.cpp b/Source/Level/Awards.cpp index 0a561e5..933f518 100644 --- a/Source/Level/Awards.cpp +++ b/Source/Level/Awards.cpp @@ -17,9 +17,10 @@ You should have received a copy of the GNU General Public License along with Lugaru. If not, see . */ -#include "Level/Awards.h" -#include "Objects/Person.h" -#include "Game.h" +#include "Level/Awards.hpp" + +#include "Game.hpp" +#include "Objects/Person.hpp" int bonus; float bonusvalue; diff --git a/Source/Level/Awards.h b/Source/Level/Awards.h deleted file mode 100644 index 882fbef..0000000 --- a/Source/Level/Awards.h +++ /dev/null @@ -1,70 +0,0 @@ -/* -Copyright (C) 2010-2016 - Lugaru contributors (see AUTHORS file) - -This file is part of Lugaru. - -Lugaru is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2 of the License, or -(at your option) any later version. - -Lugaru is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with Lugaru. If not, see . -*/ - -#ifndef AWARDS_H -#define AWARDS_H - -enum bonus_types { -#define DECLARE_BONUS(id, ...) id, -#include "Bonuses.def" -#undef DECLARE_BONUS - bonus_count -}; - -extern const char *bonus_names[bonus_count]; - -extern int bonus; -extern float bonusvalue; -extern float bonustotal; -extern float bonustime; -extern float startbonustotal; -extern float bonusnum[100]; - -extern void award_bonus(int playerid, int bonusid, int alt_value = 0); - -enum award_types { -#define DECLARE_AWARD(id, name) id, -#include "Awards.def" -#undef DECLARE_AWARD - award_count -}; - -extern const char *award_names[award_count]; - -extern int award_awards(int *); - -extern float damagetaken; -extern int numfalls; -extern int numflipfail; -extern int numseen; -extern int numresponded; -extern int numstaffattack; -extern int numswordattack; -extern int numknifeattack; -extern int numunarmedattack; -extern int numescaped; -extern int numflipped; -extern int numwallflipped; -extern int numthrowkill; -extern int numafterkill; -extern int numreversals; -extern int numattacks; -extern int maxalarmed; -#endif - diff --git a/Source/Level/Awards.hpp b/Source/Level/Awards.hpp new file mode 100644 index 0000000..ba2bdf8 --- /dev/null +++ b/Source/Level/Awards.hpp @@ -0,0 +1,70 @@ +/* +Copyright (C) 2010-2016 - Lugaru contributors (see AUTHORS file) + +This file is part of Lugaru. + +Lugaru is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +Lugaru is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with Lugaru. If not, see . +*/ + +#ifndef _AWARDS_HPP_ +#define _AWARDS_HPP_ + +enum bonus_types { +#define DECLARE_BONUS(id, ...) id, +#include "Bonuses.def" +#undef DECLARE_BONUS + bonus_count +}; + +extern const char *bonus_names[bonus_count]; + +extern int bonus; +extern float bonusvalue; +extern float bonustotal; +extern float bonustime; +extern float startbonustotal; +extern float bonusnum[100]; + +extern void award_bonus(int playerid, int bonusid, int alt_value = 0); + +enum award_types { +#define DECLARE_AWARD(id, name) id, +#include "Awards.def" +#undef DECLARE_AWARD + award_count +}; + +extern const char *award_names[award_count]; + +extern int award_awards(int *); + +extern float damagetaken; +extern int numfalls; +extern int numflipfail; +extern int numseen; +extern int numresponded; +extern int numstaffattack; +extern int numswordattack; +extern int numknifeattack; +extern int numunarmedattack; +extern int numescaped; +extern int numflipped; +extern int numwallflipped; +extern int numthrowkill; +extern int numafterkill; +extern int numreversals; +extern int numattacks; +extern int maxalarmed; +#endif + diff --git a/Source/Level/Campaign.cpp b/Source/Level/Campaign.cpp index 2aa5f17..236f631 100644 --- a/Source/Level/Campaign.cpp +++ b/Source/Level/Campaign.cpp @@ -18,9 +18,10 @@ You should have received a copy of the GNU General Public License along with Lugaru. If not, see . */ -#include "Game.h" -#include "Level/Campaign.h" -#include "Utils/Folders.h" +#include "Level/Campaign.hpp" + +#include "Game.hpp" +#include "Utils/Folders.hpp" #include diff --git a/Source/Level/Campaign.h b/Source/Level/Campaign.h deleted file mode 100644 index 3cd4d51..0000000 --- a/Source/Level/Campaign.h +++ /dev/null @@ -1,65 +0,0 @@ -/* -Copyright (C) 2003, 2010 - Wolfire Games -Copyright (C) 2010-2016 - Lugaru contributors (see AUTHORS file) - -This file is part of Lugaru. - -Lugaru is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2 of the License, or -(at your option) any later version. - -Lugaru is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with Lugaru. If not, see . -*/ - -#include -#include - -#include "Math/Quaternions.h" - -extern bool campaign; - -extern int actuallevel; - -std::vector ListCampaigns(); -void LoadCampaign(); - -class CampaignLevel -{ -private: - int width; - struct Position { - int x, y; - }; -public: - std::string mapname; - std::string description; - int choosenext; - /* - 0 = Immediately load next level at the end of this one. - 1 = Go back to the world map. - 2 = Don't bring up the Fiery loading screen. Maybe other things, I've not investigated. - */ - //int numnext; // 0 on final level. As David said: he meant to add story branching, but he eventually hadn't. - std::vector nextlevel; - Position location; - CampaignLevel(); - int getStartX(); - int getStartY(); - int getEndX(); - int getEndY(); - XYZ getCenter(); - int getWidth(); - std::istream& operator<< (std::istream& is); - friend std::istream& operator>> (std::istream& is, CampaignLevel& cl) { - return cl << is; - } -}; - -extern std::vector campaignlevels; diff --git a/Source/Level/Campaign.hpp b/Source/Level/Campaign.hpp new file mode 100644 index 0000000..5381672 --- /dev/null +++ b/Source/Level/Campaign.hpp @@ -0,0 +1,65 @@ +/* +Copyright (C) 2003, 2010 - Wolfire Games +Copyright (C) 2010-2016 - Lugaru contributors (see AUTHORS file) + +This file is part of Lugaru. + +Lugaru is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +Lugaru is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with Lugaru. If not, see . +*/ + +#include "Math/Quaternions.hpp" + +#include +#include + +extern bool campaign; + +extern int actuallevel; + +std::vector ListCampaigns(); +void LoadCampaign(); + +class CampaignLevel +{ +private: + int width; + struct Position { + int x, y; + }; +public: + std::string mapname; + std::string description; + int choosenext; + /* + 0 = Immediately load next level at the end of this one. + 1 = Go back to the world map. + 2 = Don't bring up the Fiery loading screen. Maybe other things, I've not investigated. + */ + //int numnext; // 0 on final level. As David said: he meant to add story branching, but he eventually hadn't. + std::vector nextlevel; + Position location; + CampaignLevel(); + int getStartX(); + int getStartY(); + int getEndX(); + int getEndY(); + XYZ getCenter(); + int getWidth(); + std::istream& operator<< (std::istream& is); + friend std::istream& operator>> (std::istream& is, CampaignLevel& cl) { + return cl << is; + } +}; + +extern std::vector campaignlevels; diff --git a/Source/Level/Dialog.cpp b/Source/Level/Dialog.cpp index 915fba1..a60b115 100644 --- a/Source/Level/Dialog.cpp +++ b/Source/Level/Dialog.cpp @@ -18,13 +18,13 @@ You should have received a copy of the GNU General Public License along with Lugaru. If not, see . */ -#include "Game.h" +#include "Level/Dialog.hpp" -#include "Level/Dialog.h" -#include "Objects/Person.h" +#include "Game.hpp" +#include "Objects/Person.hpp" #include "Utils/binio.h" -#include "Utils/Folders.h" -#include "Utils/Input.h" +#include "Utils/Folders.hpp" +#include "Utils/Input.hpp" extern int hostile; diff --git a/Source/Level/Dialog.h b/Source/Level/Dialog.h deleted file mode 100644 index 50691c5..0000000 --- a/Source/Level/Dialog.h +++ /dev/null @@ -1,78 +0,0 @@ -/* -Copyright (C) 2003, 2010 - Wolfire Games -Copyright (C) 2010-2016 - Lugaru contributors (see AUTHORS file) - -This file is part of Lugaru. - -Lugaru is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2 of the License, or -(at your option) any later version. - -Lugaru is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with Lugaru. If not, see . -*/ - -#ifndef _DIALOG_H_ -#define _DIALOG_H_ - -#include "stdio.h" -#include - -#include "Math/Quaternions.h" - -class DialogScene -{ -public: - DialogScene(FILE* tfile); - DialogScene(ifstream &ipstream); - void save(FILE* tfile); - - int location; - float color[3]; - int sound; - std::string text; - std::string name; - XYZ camera; - float camerayaw; - float camerapitch; - int participantfocus; - int participantaction; - XYZ participantfacing[10]; -}; - -class Dialog -{ -public: - Dialog(FILE* tfile); - Dialog(int type, std::string filename); - void tick(int id); - void play(); - void save(FILE* tfile); - - int type; - int gonethrough; - std::vector scenes; - XYZ participantlocation[10]; - float participantyaw[10]; - - static void loadDialogs(FILE*); - static void saveDialogs(FILE*); - - static bool inDialog() { return (indialogue != -1); } - static Dialog& currentDialog() { return dialogs[whichdialogue]; } - static DialogScene& currentScene() { return currentDialog().scenes[indialogue]; } - - static int indialogue; - static int whichdialogue; - static bool directing; - static float dialoguetime; - static std::vector dialogs; -}; - -#endif /*_DIALOG_H_*/ diff --git a/Source/Level/Dialog.hpp b/Source/Level/Dialog.hpp new file mode 100644 index 0000000..43bc31c --- /dev/null +++ b/Source/Level/Dialog.hpp @@ -0,0 +1,78 @@ +/* +Copyright (C) 2003, 2010 - Wolfire Games +Copyright (C) 2010-2016 - Lugaru contributors (see AUTHORS file) + +This file is part of Lugaru. + +Lugaru is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +Lugaru is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with Lugaru. If not, see . +*/ + +#ifndef _DIALOG_HPP_ +#define _DIALOG_HPP_ + +#include "Math/Quaternions.hpp" + +#include +#include + +class DialogScene +{ +public: + DialogScene(FILE* tfile); + DialogScene(ifstream &ipstream); + void save(FILE* tfile); + + int location; + float color[3]; + int sound; + std::string text; + std::string name; + XYZ camera; + float camerayaw; + float camerapitch; + int participantfocus; + int participantaction; + XYZ participantfacing[10]; +}; + +class Dialog +{ +public: + Dialog(FILE* tfile); + Dialog(int type, std::string filename); + void tick(int id); + void play(); + void save(FILE* tfile); + + int type; + int gonethrough; + std::vector scenes; + XYZ participantlocation[10]; + float participantyaw[10]; + + static void loadDialogs(FILE*); + static void saveDialogs(FILE*); + + static bool inDialog() { return (indialogue != -1); } + static Dialog& currentDialog() { return dialogs[whichdialogue]; } + static DialogScene& currentScene() { return currentDialog().scenes[indialogue]; } + + static int indialogue; + static int whichdialogue; + static bool directing; + static float dialoguetime; + static std::vector dialogs; +}; + +#endif /*_DIALOG_H_*/ diff --git a/Source/Level/Hotspot.cpp b/Source/Level/Hotspot.cpp index 1f7956e..f1b2ced 100644 --- a/Source/Level/Hotspot.cpp +++ b/Source/Level/Hotspot.cpp @@ -17,7 +17,7 @@ You should have received a copy of the GNU General Public License along with Lugaru. If not, see . */ -#include "Level/Hotspot.h" +#include "Level/Hotspot.hpp" std::vector Hotspot::hotspots; int Hotspot::current = 0; diff --git a/Source/Level/Hotspot.h b/Source/Level/Hotspot.h deleted file mode 100644 index a8ef2ec..0000000 --- a/Source/Level/Hotspot.h +++ /dev/null @@ -1,43 +0,0 @@ -/* -Copyright (C) 2003, 2010 - Wolfire Games -Copyright (C) 2010-2016 - Lugaru contributors (see AUTHORS file) - -This file is part of Lugaru. - -Lugaru is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2 of the License, or -(at your option) any later version. - -Lugaru is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with Lugaru. If not, see . -*/ - -#ifndef _HOTSPOT_H_ -#define _HOTSPOT_H_ - -#include "Math/Quaternions.h" -#include - -class Hotspot -{ -public: - static std::vector hotspots; - static int current; - static int killhotspot; - - Hotspot(); - Hotspot(XYZ position, int type, float size); - - XYZ position; - int type; - float size; - char text[256] = {0}; -}; - -#endif diff --git a/Source/Level/Hotspot.hpp b/Source/Level/Hotspot.hpp new file mode 100644 index 0000000..3629a55 --- /dev/null +++ b/Source/Level/Hotspot.hpp @@ -0,0 +1,44 @@ +/* +Copyright (C) 2003, 2010 - Wolfire Games +Copyright (C) 2010-2016 - Lugaru contributors (see AUTHORS file) + +This file is part of Lugaru. + +Lugaru is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +Lugaru is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with Lugaru. If not, see . +*/ + +#ifndef _HOTSPOT_HPP_ +#define _HOTSPOT_HPP_ + +#include "Math/Quaternions.hpp" + +#include + +class Hotspot +{ +public: + static std::vector hotspots; + static int current; + static int killhotspot; + + Hotspot(); + Hotspot(XYZ position, int type, float size); + + XYZ position; + int type; + float size; + char text[256] = {0}; +}; + +#endif diff --git a/Source/MacCompatibility.cpp b/Source/MacCompatibility.cpp index 6e47632..ac0e63c 100644 --- a/Source/MacCompatibility.cpp +++ b/Source/MacCompatibility.cpp @@ -18,12 +18,7 @@ You should have received a copy of the GNU General Public License along with Lugaru. If not, see . */ -/**> HEADER FILES <**/ -#include "MacCompatibility.h" - -#ifdef WIN32 -#include -#endif +#include "MacCompatibility.hpp" #include #include @@ -31,11 +26,16 @@ along with Lugaru. If not, see . #include #include +#ifdef WIN32 +#include +#endif + #if PLATFORM_UNIX +#include #include -#include #include -#include +#include + typedef long long __int64; typedef __int64 LARGE_INTEGER; static int QueryPerformanceFrequency(LARGE_INTEGER *liptr) diff --git a/Source/MacCompatibility.h b/Source/MacCompatibility.h deleted file mode 100644 index 26b0b60..0000000 --- a/Source/MacCompatibility.h +++ /dev/null @@ -1,97 +0,0 @@ -/* -Copyright (C) 2003, 2010 - Wolfire Games -Copyright (C) 2010-2016 - Lugaru contributors (see AUTHORS file) - -This file is part of Lugaru. - -Lugaru is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2 of the License, or -(at your option) any later version. - -Lugaru is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with Lugaru. If not, see . -*/ - -#ifndef _MACCOMPATIBLITY_H_ -#define _MACCOMPATIBLITY_H_ - -#include -#include -#include - -// stuff to make Mac code compatable with Windows/Linux/etc - -#if defined(WIN32) && !defined(strcasecmp) -#define strcasecmp(a,b) stricmp(a,b) -#endif - -#ifdef _MSC_VER -// disable warnings about double to float conversions -#pragma warning(disable:4305) -#pragma warning(disable:4244) - -// disable warnings about boolean to int conversions -#pragma warning(disable:4800) - -// disable warning about unreferenced local variables -#pragma warning(disable:4101) -#endif - -#ifndef __forceinline -# ifdef __GNUC__ -# define __forceinline inline __attribute__((always_inline)) -# endif -#endif - -struct Point { - short v; - short h; -}; - -typedef signed char SInt8; -typedef unsigned int UInt32; - - -#include "Math/Random.h" - -typedef struct AbsoluteTime { - unsigned long hi; - unsigned long lo; -} AbsoluteTime; - -AbsoluteTime UpTime(); // NOTE: returns time since app started, not system start - -typedef long Duration; - -enum { - durationMicrosecond = -1, - durationMillisecond = 1, - durationSecond = 1000, - durationMinute = 1000 * 60, - durationHour = 1000 * 60 * 60, - durationDay = 1000 * 60 * 60 * 24, - durationForever = 0x7FFFFFFF, - durationImmediate = 0, -}; - -Duration AbsoluteDeltaToDuration( AbsoluteTime& a, AbsoluteTime& b); - -#ifdef _MSC_VER -inline bool isnormal( double x) -{ - int ret = _fpclass( x); - return (ret == _FPCLASS_NN || ret == _FPCLASS_PN); -} -#else -#include -#endif - -#endif - - diff --git a/Source/MacCompatibility.hpp b/Source/MacCompatibility.hpp new file mode 100644 index 0000000..57cdc41 --- /dev/null +++ b/Source/MacCompatibility.hpp @@ -0,0 +1,98 @@ +/* +Copyright (C) 2003, 2010 - Wolfire Games +Copyright (C) 2010-2016 - Lugaru contributors (see AUTHORS file) + +This file is part of Lugaru. + +Lugaru is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +Lugaru is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with Lugaru. If not, see . +*/ + +#ifndef _MACCOMPATIBLITY_HPP_ +#define _MACCOMPATIBLITY_HPP_ + +#include "Math/Random.hpp" + +#include +#include +#include + +// stuff to make Mac code compatable with Windows/Linux/etc + +#if defined(WIN32) && !defined(strcasecmp) +#define strcasecmp(a,b) stricmp(a,b) +#endif + +#ifdef _MSC_VER +// disable warnings about double to float conversions +#pragma warning(disable:4305) +#pragma warning(disable:4244) + +// disable warnings about boolean to int conversions +#pragma warning(disable:4800) + +// disable warning about unreferenced local variables +#pragma warning(disable:4101) +#endif + +#ifndef __forceinline +# ifdef __GNUC__ +# define __forceinline inline __attribute__((always_inline)) +# endif +#endif + +struct Point { + short v; + short h; +}; + +typedef signed char SInt8; +typedef unsigned int UInt32; + + + +typedef struct AbsoluteTime { + unsigned long hi; + unsigned long lo; +} AbsoluteTime; + +AbsoluteTime UpTime(); // NOTE: returns time since app started, not system start + +typedef long Duration; + +enum { + durationMicrosecond = -1, + durationMillisecond = 1, + durationSecond = 1000, + durationMinute = 1000 * 60, + durationHour = 1000 * 60 * 60, + durationDay = 1000 * 60 * 60 * 24, + durationForever = 0x7FFFFFFF, + durationImmediate = 0, +}; + +Duration AbsoluteDeltaToDuration( AbsoluteTime& a, AbsoluteTime& b); + +#ifdef _MSC_VER +inline bool isnormal( double x) +{ + int ret = _fpclass( x); + return (ret == _FPCLASS_NN || ret == _FPCLASS_PN); +} +#else +#include +#endif + +#endif + + diff --git a/Source/Math/Frustum.cpp b/Source/Math/Frustum.cpp index 164074b..e8b1366 100644 --- a/Source/Math/Frustum.cpp +++ b/Source/Math/Frustum.cpp @@ -18,11 +18,11 @@ You should have received a copy of the GNU General Public License along with Lugaru. If not, see . */ -#include "Math/Frustum.h" -#include +#include "Math/Frustum.hpp" -#include "Graphic/gamegl.h" +#include "Graphic/gamegl.hpp" +#include void FRUSTUM:: GetFrustum() diff --git a/Source/Math/Frustum.h b/Source/Math/Frustum.h deleted file mode 100644 index 918a047..0000000 --- a/Source/Math/Frustum.h +++ /dev/null @@ -1,34 +0,0 @@ -/* -Copyright (C) 2003, 2010 - Wolfire Games -Copyright (C) 2010-2016 - Lugaru contributors (see AUTHORS file) - -This file is part of Lugaru. - -Lugaru is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2 of the License, or -(at your option) any later version. - -Lugaru is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with Lugaru. If not, see . -*/ - -#ifndef FRUSTUM_H -#define FRUSTUM_H - -class FRUSTUM -{ -public: - float frustum[6][4]; - void GetFrustum(); - int CubeInFrustum(float, float, float, float); - int CubeInFrustum(float, float, float, float, float); - int SphereInFrustum(float, float, float, float); -}; - -#endif diff --git a/Source/Math/Frustum.hpp b/Source/Math/Frustum.hpp new file mode 100644 index 0000000..79f4e48 --- /dev/null +++ b/Source/Math/Frustum.hpp @@ -0,0 +1,34 @@ +/* +Copyright (C) 2003, 2010 - Wolfire Games +Copyright (C) 2010-2016 - Lugaru contributors (see AUTHORS file) + +This file is part of Lugaru. + +Lugaru is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +Lugaru is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with Lugaru. If not, see . +*/ + +#ifndef _FRUSTUM_HPP_ +#define _FRUSTUM_HPP_ + +class FRUSTUM +{ +public: + float frustum[6][4]; + void GetFrustum(); + int CubeInFrustum(float, float, float, float); + int CubeInFrustum(float, float, float, float, float); + int SphereInFrustum(float, float, float, float); +}; + +#endif diff --git a/Source/Math/PhysicsMath.h b/Source/Math/PhysicsMath.h deleted file mode 100644 index 7dc9461..0000000 --- a/Source/Math/PhysicsMath.h +++ /dev/null @@ -1,765 +0,0 @@ -/* -Copyright (C) 2003, 2010 - Wolfire Games -Copyright (C) 2010-2016 - Lugaru contributors (see AUTHORS file) - -This file is part of Lugaru. - -Lugaru is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2 of the License, or -(at your option) any later version. - -Lugaru is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with Lugaru. If not, see . -*/ - -#ifndef _PHYSICSMATH_H_ -#define _PHYSICSMATH_H_ - -//#include - -#include "MacCompatibility.h" - -//------------------------------------------------------------------------// -// Misc. Constants -//------------------------------------------------------------------------// - -float const pi = 3.14159265f; -float const g = -32.174f; // acceleration due to gravity, ft/s^2 -float const rho = 0.0023769f; // desity of air at sea level, slugs/ft^3 -float const tol = 0.0000000001f; // float type tolerance - - -//------------------------------------------------------------------------// -// Misc. Functions -//------------------------------------------------------------------------// -inline float DegreesToRadians(float deg); -inline float RadiansToDegrees(float rad); - -inline float DegreesToRadians(float deg) -{ - return deg * pi / 180.0f; -} - -inline float RadiansToDegrees(float rad) -{ - return rad * 180.0f / pi; -} - -//------------------------------------------------------------------------// -// Vector Class and vector functions -//------------------------------------------------------------------------// -class Vector -{ -public: - float x; - float y; - float z; - - Vector(void); - Vector(float xi, float yi, float zi); - - float Magnitude(void); - void Normalize(void); - void Reverse(void); - - Vector& operator+=(Vector u); // vector addition - Vector& operator-=(Vector u); // vector subtraction - Vector& operator*=(float s); // scalar multiply - Vector& operator/=(float s); // scalar divide - - Vector operator-(void); - -}; - -inline Vector operator+(Vector u, Vector v); -inline Vector operator-(Vector u, Vector v); -inline Vector operator^(Vector u, Vector v); -inline float operator*(Vector u, Vector v); -inline Vector operator*(float s, Vector u); -inline Vector operator*(Vector u, float s); -inline Vector operator/(Vector u, float s); -inline float TripleScalarProduct(Vector u, Vector v, Vector w); -/* -float fast_sqrt2 (register float arg); -float fast_sqrt2 (register float arg) -{ -// Can replace with slower return std::sqrt(arg); -register float result; - -if (arg == 0.0) return 0.0; - -asm { -frsqrte result,arg // Calculate Square root -} - -// Newton Rhapson iterations. -result = result + 0.5 * result * (1.0 - arg * result * result); -result = result + 0.5 * result * (1.0 - arg * result * result); - -return result * arg; -} -*/ -inline Vector::Vector(void) -{ - x = 0; - y = 0; - z = 0; -} - -inline Vector::Vector(float xi, float yi, float zi) -{ - x = xi; - y = yi; - z = zi; -} - -inline float Vector::Magnitude(void) -{ - return (float) sqrt(x * x + y * y + z * z); -} - -inline void Vector::Normalize(void) -{ - float m = (float) sqrt(x * x + y * y + z * z); - if (m <= tol) - m = 1; - x /= m; - y /= m; - z /= m; - - if (fabs(x) < tol) - x = 0.0f; - if (fabs(y) < tol) - y = 0.0f; - if (fabs(z) < tol) - z = 0.0f; -} - -inline void Vector::Reverse(void) -{ - x = -x; - y = -y; - z = -z; -} - -inline Vector& Vector::operator+=(Vector u) -{ - x += u.x; - y += u.y; - z += u.z; - return *this; -} - -inline Vector& Vector::operator-=(Vector u) -{ - x -= u.x; - y -= u.y; - z -= u.z; - return *this; -} - -inline Vector& Vector::operator*=(float s) -{ - x *= s; - y *= s; - z *= s; - return *this; -} - -inline Vector& Vector::operator/=(float s) -{ - x /= s; - y /= s; - z /= s; - return *this; -} - -inline Vector Vector::operator-(void) -{ - return Vector(-x, -y, -z); -} - - -inline Vector operator+(Vector u, Vector v) -{ - return Vector(u.x + v.x, u.y + v.y, u.z + v.z); -} - -inline Vector operator-(Vector u, Vector v) -{ - return Vector(u.x - v.x, u.y - v.y, u.z - v.z); -} - -// Vector cross product (u cross v) -inline Vector operator^(Vector u, Vector v) -{ - return Vector( u.y * v.z - u.z * v.y, - -u.x * v.z + u.z * v.x, - u.x * v.y - u.y * v.x ); -} - -// Vector dot product -inline float operator*(Vector u, Vector v) -{ - return (u.x * v.x + u.y * v.y + u.z * v.z); -} - -inline Vector operator*(float s, Vector u) -{ - return Vector(u.x * s, u.y * s, u.z * s); -} - -inline Vector operator*(Vector u, float s) -{ - return Vector(u.x * s, u.y * s, u.z * s); -} - -inline Vector operator/(Vector u, float s) -{ - return Vector(u.x / s, u.y / s, u.z / s); -} - -// triple scalar product (u dot (v cross w)) -inline float TripleScalarProduct(Vector u, Vector v, Vector w) -{ - return float( (u.x * (v.y * w.z - v.z * w.y)) + - (u.y * (-v.x * w.z + v.z * w.x)) + - (u.z * (v.x * w.y - v.y * w.x)) ); - //return u*(v^w); - -} - - - -//------------------------------------------------------------------------// -// Matrix Class and matrix functions -//------------------------------------------------------------------------// - -class Matrix3x3 -{ -public: - // elements eij: i -> row, j -> column - float e11, e12, e13, e21, e22, e23, e31, e32, e33; - - Matrix3x3(void); - Matrix3x3( float r1c1, float r1c2, float r1c3, - float r2c1, float r2c2, float r2c3, - float r3c1, float r3c2, float r3c3 ); - - float det(void); - Matrix3x3 Transpose(void); - Matrix3x3 Inverse(void); - - Matrix3x3& operator+=(Matrix3x3 m); - Matrix3x3& operator-=(Matrix3x3 m); - Matrix3x3& operator*=(float s); - Matrix3x3& operator/=(float s); -}; - -inline Matrix3x3 operator+(Matrix3x3 m1, Matrix3x3 m2); -inline Matrix3x3 operator-(Matrix3x3 m1, Matrix3x3 m2); -inline Matrix3x3 operator/(Matrix3x3 m, float s); -inline Matrix3x3 operator*(Matrix3x3 m1, Matrix3x3 m2); -inline Matrix3x3 operator*(Matrix3x3 m, float s); -inline Matrix3x3 operator*(float s, Matrix3x3 m); -inline Vector operator*(Matrix3x3 m, Vector u); -inline Vector operator*(Vector u, Matrix3x3 m); - - - - - -inline Matrix3x3::Matrix3x3(void) -{ - e11 = 0; - e12 = 0; - e13 = 0; - e21 = 0; - e22 = 0; - e23 = 0; - e31 = 0; - e32 = 0; - e33 = 0; -} - -inline Matrix3x3::Matrix3x3( float r1c1, float r1c2, float r1c3, - float r2c1, float r2c2, float r2c3, - float r3c1, float r3c2, float r3c3 ) -{ - e11 = r1c1; - e12 = r1c2; - e13 = r1c3; - e21 = r2c1; - e22 = r2c2; - e23 = r2c3; - e31 = r3c1; - e32 = r3c2; - e33 = r3c3; -} - -inline float Matrix3x3::det(void) -{ - return e11 * e22 * e33 - - e11 * e32 * e23 + - e21 * e32 * e13 - - e21 * e12 * e33 + - e31 * e12 * e23 - - e31 * e22 * e13; -} - -inline Matrix3x3 Matrix3x3::Transpose(void) -{ - return Matrix3x3(e11, e21, e31, e12, e22, e32, e13, e23, e33); -} - -inline Matrix3x3 Matrix3x3::Inverse(void) -{ - float d = e11 * e22 * e33 - - e11 * e32 * e23 + - e21 * e32 * e13 - - e21 * e12 * e33 + - e31 * e12 * e23 - - e31 * e22 * e13; - - if (d == 0) - d = 1; - - return Matrix3x3( (e22 * e33 - e23 * e32) / d, - -(e12 * e33 - e13 * e32) / d, - (e12 * e23 - e13 * e22) / d, - -(e21 * e33 - e23 * e31) / d, - (e11 * e33 - e13 * e31) / d, - -(e11 * e23 - e13 * e21) / d, - (e21 * e32 - e22 * e31) / d, - -(e11 * e32 - e12 * e31) / d, - (e11 * e22 - e12 * e21) / d ); -} - -inline Matrix3x3& Matrix3x3::operator+=(Matrix3x3 m) -{ - e11 += m.e11; - e12 += m.e12; - e13 += m.e13; - e21 += m.e21; - e22 += m.e22; - e23 += m.e23; - e31 += m.e31; - e32 += m.e32; - e33 += m.e33; - return *this; -} - -inline Matrix3x3& Matrix3x3::operator-=(Matrix3x3 m) -{ - e11 -= m.e11; - e12 -= m.e12; - e13 -= m.e13; - e21 -= m.e21; - e22 -= m.e22; - e23 -= m.e23; - e31 -= m.e31; - e32 -= m.e32; - e33 -= m.e33; - return *this; -} - -inline Matrix3x3& Matrix3x3::operator*=(float s) -{ - e11 *= s; - e12 *= s; - e13 *= s; - e21 *= s; - e22 *= s; - e23 *= s; - e31 *= s; - e32 *= s; - e33 *= s; - return *this; -} - -inline Matrix3x3& Matrix3x3::operator/=(float s) -{ - e11 /= s; - e12 /= s; - e13 /= s; - e21 /= s; - e22 /= s; - e23 /= s; - e31 /= s; - e32 /= s; - e33 /= s; - return *this; -} - -inline Matrix3x3 operator+(Matrix3x3 m1, Matrix3x3 m2) -{ - return Matrix3x3( m1.e11 + m2.e11, - m1.e12 + m2.e12, - m1.e13 + m2.e13, - m1.e21 + m2.e21, - m1.e22 + m2.e22, - m1.e23 + m2.e23, - m1.e31 + m2.e31, - m1.e32 + m2.e32, - m1.e33 + m2.e33); -} - -inline Matrix3x3 operator-(Matrix3x3 m1, Matrix3x3 m2) -{ - return Matrix3x3( m1.e11 - m2.e11, - m1.e12 - m2.e12, - m1.e13 - m2.e13, - m1.e21 - m2.e21, - m1.e22 - m2.e22, - m1.e23 - m2.e23, - m1.e31 - m2.e31, - m1.e32 - m2.e32, - m1.e33 - m2.e33); -} - -inline Matrix3x3 operator/(Matrix3x3 m, float s) -{ - return Matrix3x3( m.e11 / s, - m.e12 / s, - m.e13 / s, - m.e21 / s, - m.e22 / s, - m.e23 / s, - m.e31 / s, - m.e32 / s, - m.e33 / s); -} - -inline Matrix3x3 operator*(Matrix3x3 m1, Matrix3x3 m2) -{ - return Matrix3x3( m1.e11 * m2.e11 + m1.e12 * m2.e21 + m1.e13 * m2.e31, - m1.e11 * m2.e12 + m1.e12 * m2.e22 + m1.e13 * m2.e32, - m1.e11 * m2.e13 + m1.e12 * m2.e23 + m1.e13 * m2.e33, - m1.e21 * m2.e11 + m1.e22 * m2.e21 + m1.e23 * m2.e31, - m1.e21 * m2.e12 + m1.e22 * m2.e22 + m1.e23 * m2.e32, - m1.e21 * m2.e13 + m1.e22 * m2.e23 + m1.e23 * m2.e33, - m1.e31 * m2.e11 + m1.e32 * m2.e21 + m1.e33 * m2.e31, - m1.e31 * m2.e12 + m1.e32 * m2.e22 + m1.e33 * m2.e32, - m1.e31 * m2.e13 + m1.e32 * m2.e23 + m1.e33 * m2.e33 ); -} - -inline Matrix3x3 operator*(Matrix3x3 m, float s) -{ - return Matrix3x3( m.e11 * s, - m.e12 * s, - m.e13 * s, - m.e21 * s, - m.e22 * s, - m.e23 * s, - m.e31 * s, - m.e32 * s, - m.e33 * s); -} - -inline Matrix3x3 operator*(float s, Matrix3x3 m) -{ - return Matrix3x3( m.e11 * s, - m.e12 * s, - m.e13 * s, - m.e21 * s, - m.e22 * s, - m.e23 * s, - m.e31 * s, - m.e32 * s, - m.e33 * s); -} - -inline Vector operator*(Matrix3x3 m, Vector u) -{ - return Vector( m.e11 * u.x + m.e12 * u.y + m.e13 * u.z, - m.e21 * u.x + m.e22 * u.y + m.e23 * u.z, - m.e31 * u.x + m.e32 * u.y + m.e33 * u.z); -} - -inline Vector operator*(Vector u, Matrix3x3 m) -{ - return Vector( u.x * m.e11 + u.y * m.e21 + u.z * m.e31, - u.x * m.e12 + u.y * m.e22 + u.z * m.e32, - u.x * m.e13 + u.y * m.e23 + u.z * m.e33); -} - -//------------------------------------------------------------------------// -// Quaternion Class and Quaternion functions -//------------------------------------------------------------------------// - -class Quaternion -{ -public: - float n; // number (scalar) part - Vector v; // vector part: v.x, v.y, v.z - - Quaternion(void); - Quaternion(float e0, float e1, float e2, float e3); - - float Magnitude(void); - Vector GetVector(void); - float GetScalar(void); - Quaternion operator+=(Quaternion q); - Quaternion operator-=(Quaternion q); - Quaternion operator*=(float s); - Quaternion operator/=(float s); - Quaternion operator~(void) const { - return Quaternion(n, -v.x, -v.y, -v.z); - } -}; - -inline Quaternion operator+(Quaternion q1, Quaternion q2); -inline Quaternion operator-(Quaternion q1, Quaternion q2); -inline Quaternion operator*(Quaternion q1, Quaternion q2); -inline Quaternion operator*(Quaternion q, float s); -inline Quaternion operator*(float s, Quaternion q); -inline Quaternion operator*(Quaternion q, Vector v); -inline Quaternion operator*(Vector v, Quaternion q); -inline Quaternion operator/(Quaternion q, float s); -inline float QGetAngle(Quaternion q); -inline Vector QGetAxis(Quaternion q); -inline Quaternion QRotate(Quaternion q1, Quaternion q2); -inline Vector QVRotate(Quaternion q, Vector v); -inline Quaternion MakeQFromEulerAngles(float x, float y, float z); -inline Vector MakeEulerAnglesFromQ(Quaternion q); - - -inline Quaternion::Quaternion(void) -{ - n = 0; - v.x = 0; - v.y = 0; - v.z = 0; -} - -inline Quaternion::Quaternion(float e0, float e1, float e2, float e3) -{ - n = e0; - v.x = e1; - v.y = e2; - v.z = e3; -} - -inline float Quaternion::Magnitude(void) -{ - return (float) sqrt(n * n + v.x * v.x + v.y * v.y + v.z * v.z); -} - -inline Vector Quaternion::GetVector(void) -{ - return Vector(v.x, v.y, v.z); -} - -inline float Quaternion::GetScalar(void) -{ - return n; -} - -inline Quaternion Quaternion::operator+=(Quaternion q) -{ - n += q.n; - v.x += q.v.x; - v.y += q.v.y; - v.z += q.v.z; - return *this; -} - -inline Quaternion Quaternion::operator-=(Quaternion q) -{ - n -= q.n; - v.x -= q.v.x; - v.y -= q.v.y; - v.z -= q.v.z; - return *this; -} - -inline Quaternion Quaternion::operator*=(float s) -{ - n *= s; - v.x *= s; - v.y *= s; - v.z *= s; - return *this; -} - -inline Quaternion Quaternion::operator/=(float s) -{ - n /= s; - v.x /= s; - v.y /= s; - v.z /= s; - return *this; -} - -/*inline Quaternion Quaternion::operator~() -{ -return Quaternion(n, -v.x, -v.y, -v.z); -}*/ - -inline Quaternion operator+(Quaternion q1, Quaternion q2) -{ - return Quaternion( q1.n + q2.n, - q1.v.x + q2.v.x, - q1.v.y + q2.v.y, - q1.v.z + q2.v.z); -} - -inline Quaternion operator-(Quaternion q1, Quaternion q2) -{ - return Quaternion( q1.n - q2.n, - q1.v.x - q2.v.x, - q1.v.y - q2.v.y, - q1.v.z - q2.v.z); -} - -inline Quaternion operator*(Quaternion q1, Quaternion q2) -{ - return Quaternion( q1.n * q2.n - q1.v.x * q2.v.x - q1.v.y * q2.v.y - q1.v.z * q2.v.z, - q1.n * q2.v.x + q1.v.x * q2.n + q1.v.y * q2.v.z - q1.v.z * q2.v.y, - q1.n * q2.v.y + q1.v.y * q2.n + q1.v.z * q2.v.x - q1.v.x * q2.v.z, - q1.n * q2.v.z + q1.v.z * q2.n + q1.v.x * q2.v.y - q1.v.y * q2.v.x); -} - -inline Quaternion operator*(Quaternion q, float s) -{ - return Quaternion(q.n * s, q.v.x * s, q.v.y * s, q.v.z * s); -} - -inline Quaternion operator*(float s, Quaternion q) -{ - return Quaternion(q.n * s, q.v.x * s, q.v.y * s, q.v.z * s); -} - -inline Quaternion operator*(Quaternion q, Vector v) -{ - return Quaternion( -(q.v.x * v.x + q.v.y * v.y + q.v.z * v.z), - q.n * v.x + q.v.y * v.z - q.v.z * v.y, - q.n * v.y + q.v.z * v.x - q.v.x * v.z, - q.n * v.z + q.v.x * v.y - q.v.y * v.x); -} - -inline Quaternion operator*(Vector v, Quaternion q) -{ - return Quaternion( -(q.v.x * v.x + q.v.y * v.y + q.v.z * v.z), - q.n * v.x + q.v.z * v.y - q.v.y * v.z, - q.n * v.y + q.v.x * v.z - q.v.z * v.x, - q.n * v.z + q.v.y * v.x - q.v.x * v.y); -} - -inline Quaternion operator/(Quaternion q, float s) -{ - return Quaternion(q.n / s, q.v.x / s, q.v.y / s, q.v.z / s); -} - -inline float QGetAngle(Quaternion q) -{ - return (float) (2 * acosf(q.n)); -} - -inline Vector QGetAxis(Quaternion q) -{ - Vector v; - float m; - - v = q.GetVector(); - m = v.Magnitude(); - - if (m <= tol) - return Vector(); - else - return v / m; -} - -inline Quaternion QRotate(Quaternion q1, Quaternion q2) -{ - return q1 * q2 * (~q1); -} - -inline Vector QVRotate(Quaternion q, Vector v) -{ - Quaternion t; - - - t = q * v * (~q); - - return t.GetVector(); -} - -inline Quaternion MakeQFromEulerAngles(float x, float y, float z) -{ - Quaternion q; - double roll = DegreesToRadians(x); - double pitch = DegreesToRadians(y); - double yaw = DegreesToRadians(z); - - double cyaw, cpitch, croll, syaw, spitch, sroll; - double cyawcpitch, syawspitch, cyawspitch, syawcpitch; - - cyaw = cos(0.5f * yaw); - cpitch = cos(0.5f * pitch); - croll = cos(0.5f * roll); - syaw = sin(0.5f * yaw); - spitch = sin(0.5f * pitch); - sroll = sin(0.5f * roll); - - cyawcpitch = cyaw * cpitch; - syawspitch = syaw * spitch; - cyawspitch = cyaw * spitch; - syawcpitch = syaw * cpitch; - - q.n = (float) (cyawcpitch * croll + syawspitch * sroll); - q.v.x = (float) (cyawcpitch * sroll - syawspitch * croll); - q.v.y = (float) (cyawspitch * croll + syawcpitch * sroll); - q.v.z = (float) (syawcpitch * croll - cyawspitch * sroll); - - return q; -} - -inline Vector MakeEulerAnglesFromQ(Quaternion q) -{ - double r11, r21, r31, r32, r33; - double q00, q11, q22, q33; - double tmp; - Vector u; - - q00 = q.n * q.n; - q11 = q.v.x * q.v.x; - q22 = q.v.y * q.v.y; - q33 = q.v.z * q.v.z; - - r11 = q00 + q11 - q22 - q33; - r21 = 2 * (q.v.x * q.v.y + q.n * q.v.z); - r31 = 2 * (q.v.x * q.v.z - q.n * q.v.y); - r32 = 2 * (q.v.y * q.v.z + q.n * q.v.x); - r33 = q00 - q11 - q22 + q33; - - tmp = fabs(r31); - if (tmp > 0.999999) { - double r12 = 2 * (q.v.x * q.v.y - q.n * q.v.z); - double r13 = 2 * (q.v.x * q.v.z + q.n * q.v.y); - - u.x = RadiansToDegrees(0.0f); //roll - u.y = RadiansToDegrees((float) (-(pi / 2) * r31 / tmp)); // pitch - u.z = RadiansToDegrees((float) atan2(-r12, -r31 * r13)); // yaw - return u; - } - - u.x = RadiansToDegrees((float) atan2(r32, r33)); // roll - u.y = RadiansToDegrees((float) asinf(-r31)); // pitch - u.z = RadiansToDegrees((float) atan2(r21, r11)); // yaw - return u; - - -} - - - - - -#endif diff --git a/Source/Math/PhysicsMath.hpp b/Source/Math/PhysicsMath.hpp new file mode 100644 index 0000000..6d1e5a6 --- /dev/null +++ b/Source/Math/PhysicsMath.hpp @@ -0,0 +1,763 @@ +/* +Copyright (C) 2003, 2010 - Wolfire Games +Copyright (C) 2010-2016 - Lugaru contributors (see AUTHORS file) + +This file is part of Lugaru. + +Lugaru is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +Lugaru is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with Lugaru. If not, see . +*/ + +#ifndef _PHYSICSMATH_HPP_ +#define _PHYSICSMATH_HPP_ + +#include "MacCompatibility.hpp" + +//------------------------------------------------------------------------// +// Misc. Constants +//------------------------------------------------------------------------// + +float const pi = 3.14159265f; +float const g = -32.174f; // acceleration due to gravity, ft/s^2 +float const rho = 0.0023769f; // desity of air at sea level, slugs/ft^3 +float const tol = 0.0000000001f; // float type tolerance + + +//------------------------------------------------------------------------// +// Misc. Functions +//------------------------------------------------------------------------// +inline float DegreesToRadians(float deg); +inline float RadiansToDegrees(float rad); + +inline float DegreesToRadians(float deg) +{ + return deg * pi / 180.0f; +} + +inline float RadiansToDegrees(float rad) +{ + return rad * 180.0f / pi; +} + +//------------------------------------------------------------------------// +// Vector Class and vector functions +//------------------------------------------------------------------------// +class Vector +{ +public: + float x; + float y; + float z; + + Vector(void); + Vector(float xi, float yi, float zi); + + float Magnitude(void); + void Normalize(void); + void Reverse(void); + + Vector& operator+=(Vector u); // vector addition + Vector& operator-=(Vector u); // vector subtraction + Vector& operator*=(float s); // scalar multiply + Vector& operator/=(float s); // scalar divide + + Vector operator-(void); + +}; + +inline Vector operator+(Vector u, Vector v); +inline Vector operator-(Vector u, Vector v); +inline Vector operator^(Vector u, Vector v); +inline float operator*(Vector u, Vector v); +inline Vector operator*(float s, Vector u); +inline Vector operator*(Vector u, float s); +inline Vector operator/(Vector u, float s); +inline float TripleScalarProduct(Vector u, Vector v, Vector w); +/* +float fast_sqrt2 (register float arg); +float fast_sqrt2 (register float arg) +{ +// Can replace with slower return std::sqrt(arg); +register float result; + +if (arg == 0.0) return 0.0; + +asm { +frsqrte result,arg // Calculate Square root +} + +// Newton Rhapson iterations. +result = result + 0.5 * result * (1.0 - arg * result * result); +result = result + 0.5 * result * (1.0 - arg * result * result); + +return result * arg; +} +*/ +inline Vector::Vector(void) +{ + x = 0; + y = 0; + z = 0; +} + +inline Vector::Vector(float xi, float yi, float zi) +{ + x = xi; + y = yi; + z = zi; +} + +inline float Vector::Magnitude(void) +{ + return (float) sqrt(x * x + y * y + z * z); +} + +inline void Vector::Normalize(void) +{ + float m = (float) sqrt(x * x + y * y + z * z); + if (m <= tol) + m = 1; + x /= m; + y /= m; + z /= m; + + if (fabs(x) < tol) + x = 0.0f; + if (fabs(y) < tol) + y = 0.0f; + if (fabs(z) < tol) + z = 0.0f; +} + +inline void Vector::Reverse(void) +{ + x = -x; + y = -y; + z = -z; +} + +inline Vector& Vector::operator+=(Vector u) +{ + x += u.x; + y += u.y; + z += u.z; + return *this; +} + +inline Vector& Vector::operator-=(Vector u) +{ + x -= u.x; + y -= u.y; + z -= u.z; + return *this; +} + +inline Vector& Vector::operator*=(float s) +{ + x *= s; + y *= s; + z *= s; + return *this; +} + +inline Vector& Vector::operator/=(float s) +{ + x /= s; + y /= s; + z /= s; + return *this; +} + +inline Vector Vector::operator-(void) +{ + return Vector(-x, -y, -z); +} + + +inline Vector operator+(Vector u, Vector v) +{ + return Vector(u.x + v.x, u.y + v.y, u.z + v.z); +} + +inline Vector operator-(Vector u, Vector v) +{ + return Vector(u.x - v.x, u.y - v.y, u.z - v.z); +} + +// Vector cross product (u cross v) +inline Vector operator^(Vector u, Vector v) +{ + return Vector( u.y * v.z - u.z * v.y, + -u.x * v.z + u.z * v.x, + u.x * v.y - u.y * v.x ); +} + +// Vector dot product +inline float operator*(Vector u, Vector v) +{ + return (u.x * v.x + u.y * v.y + u.z * v.z); +} + +inline Vector operator*(float s, Vector u) +{ + return Vector(u.x * s, u.y * s, u.z * s); +} + +inline Vector operator*(Vector u, float s) +{ + return Vector(u.x * s, u.y * s, u.z * s); +} + +inline Vector operator/(Vector u, float s) +{ + return Vector(u.x / s, u.y / s, u.z / s); +} + +// triple scalar product (u dot (v cross w)) +inline float TripleScalarProduct(Vector u, Vector v, Vector w) +{ + return float( (u.x * (v.y * w.z - v.z * w.y)) + + (u.y * (-v.x * w.z + v.z * w.x)) + + (u.z * (v.x * w.y - v.y * w.x)) ); + //return u*(v^w); + +} + + + +//------------------------------------------------------------------------// +// Matrix Class and matrix functions +//------------------------------------------------------------------------// + +class Matrix3x3 +{ +public: + // elements eij: i -> row, j -> column + float e11, e12, e13, e21, e22, e23, e31, e32, e33; + + Matrix3x3(void); + Matrix3x3( float r1c1, float r1c2, float r1c3, + float r2c1, float r2c2, float r2c3, + float r3c1, float r3c2, float r3c3 ); + + float det(void); + Matrix3x3 Transpose(void); + Matrix3x3 Inverse(void); + + Matrix3x3& operator+=(Matrix3x3 m); + Matrix3x3& operator-=(Matrix3x3 m); + Matrix3x3& operator*=(float s); + Matrix3x3& operator/=(float s); +}; + +inline Matrix3x3 operator+(Matrix3x3 m1, Matrix3x3 m2); +inline Matrix3x3 operator-(Matrix3x3 m1, Matrix3x3 m2); +inline Matrix3x3 operator/(Matrix3x3 m, float s); +inline Matrix3x3 operator*(Matrix3x3 m1, Matrix3x3 m2); +inline Matrix3x3 operator*(Matrix3x3 m, float s); +inline Matrix3x3 operator*(float s, Matrix3x3 m); +inline Vector operator*(Matrix3x3 m, Vector u); +inline Vector operator*(Vector u, Matrix3x3 m); + + + + + +inline Matrix3x3::Matrix3x3(void) +{ + e11 = 0; + e12 = 0; + e13 = 0; + e21 = 0; + e22 = 0; + e23 = 0; + e31 = 0; + e32 = 0; + e33 = 0; +} + +inline Matrix3x3::Matrix3x3( float r1c1, float r1c2, float r1c3, + float r2c1, float r2c2, float r2c3, + float r3c1, float r3c2, float r3c3 ) +{ + e11 = r1c1; + e12 = r1c2; + e13 = r1c3; + e21 = r2c1; + e22 = r2c2; + e23 = r2c3; + e31 = r3c1; + e32 = r3c2; + e33 = r3c3; +} + +inline float Matrix3x3::det(void) +{ + return e11 * e22 * e33 - + e11 * e32 * e23 + + e21 * e32 * e13 - + e21 * e12 * e33 + + e31 * e12 * e23 - + e31 * e22 * e13; +} + +inline Matrix3x3 Matrix3x3::Transpose(void) +{ + return Matrix3x3(e11, e21, e31, e12, e22, e32, e13, e23, e33); +} + +inline Matrix3x3 Matrix3x3::Inverse(void) +{ + float d = e11 * e22 * e33 - + e11 * e32 * e23 + + e21 * e32 * e13 - + e21 * e12 * e33 + + e31 * e12 * e23 - + e31 * e22 * e13; + + if (d == 0) + d = 1; + + return Matrix3x3( (e22 * e33 - e23 * e32) / d, + -(e12 * e33 - e13 * e32) / d, + (e12 * e23 - e13 * e22) / d, + -(e21 * e33 - e23 * e31) / d, + (e11 * e33 - e13 * e31) / d, + -(e11 * e23 - e13 * e21) / d, + (e21 * e32 - e22 * e31) / d, + -(e11 * e32 - e12 * e31) / d, + (e11 * e22 - e12 * e21) / d ); +} + +inline Matrix3x3& Matrix3x3::operator+=(Matrix3x3 m) +{ + e11 += m.e11; + e12 += m.e12; + e13 += m.e13; + e21 += m.e21; + e22 += m.e22; + e23 += m.e23; + e31 += m.e31; + e32 += m.e32; + e33 += m.e33; + return *this; +} + +inline Matrix3x3& Matrix3x3::operator-=(Matrix3x3 m) +{ + e11 -= m.e11; + e12 -= m.e12; + e13 -= m.e13; + e21 -= m.e21; + e22 -= m.e22; + e23 -= m.e23; + e31 -= m.e31; + e32 -= m.e32; + e33 -= m.e33; + return *this; +} + +inline Matrix3x3& Matrix3x3::operator*=(float s) +{ + e11 *= s; + e12 *= s; + e13 *= s; + e21 *= s; + e22 *= s; + e23 *= s; + e31 *= s; + e32 *= s; + e33 *= s; + return *this; +} + +inline Matrix3x3& Matrix3x3::operator/=(float s) +{ + e11 /= s; + e12 /= s; + e13 /= s; + e21 /= s; + e22 /= s; + e23 /= s; + e31 /= s; + e32 /= s; + e33 /= s; + return *this; +} + +inline Matrix3x3 operator+(Matrix3x3 m1, Matrix3x3 m2) +{ + return Matrix3x3( m1.e11 + m2.e11, + m1.e12 + m2.e12, + m1.e13 + m2.e13, + m1.e21 + m2.e21, + m1.e22 + m2.e22, + m1.e23 + m2.e23, + m1.e31 + m2.e31, + m1.e32 + m2.e32, + m1.e33 + m2.e33); +} + +inline Matrix3x3 operator-(Matrix3x3 m1, Matrix3x3 m2) +{ + return Matrix3x3( m1.e11 - m2.e11, + m1.e12 - m2.e12, + m1.e13 - m2.e13, + m1.e21 - m2.e21, + m1.e22 - m2.e22, + m1.e23 - m2.e23, + m1.e31 - m2.e31, + m1.e32 - m2.e32, + m1.e33 - m2.e33); +} + +inline Matrix3x3 operator/(Matrix3x3 m, float s) +{ + return Matrix3x3( m.e11 / s, + m.e12 / s, + m.e13 / s, + m.e21 / s, + m.e22 / s, + m.e23 / s, + m.e31 / s, + m.e32 / s, + m.e33 / s); +} + +inline Matrix3x3 operator*(Matrix3x3 m1, Matrix3x3 m2) +{ + return Matrix3x3( m1.e11 * m2.e11 + m1.e12 * m2.e21 + m1.e13 * m2.e31, + m1.e11 * m2.e12 + m1.e12 * m2.e22 + m1.e13 * m2.e32, + m1.e11 * m2.e13 + m1.e12 * m2.e23 + m1.e13 * m2.e33, + m1.e21 * m2.e11 + m1.e22 * m2.e21 + m1.e23 * m2.e31, + m1.e21 * m2.e12 + m1.e22 * m2.e22 + m1.e23 * m2.e32, + m1.e21 * m2.e13 + m1.e22 * m2.e23 + m1.e23 * m2.e33, + m1.e31 * m2.e11 + m1.e32 * m2.e21 + m1.e33 * m2.e31, + m1.e31 * m2.e12 + m1.e32 * m2.e22 + m1.e33 * m2.e32, + m1.e31 * m2.e13 + m1.e32 * m2.e23 + m1.e33 * m2.e33 ); +} + +inline Matrix3x3 operator*(Matrix3x3 m, float s) +{ + return Matrix3x3( m.e11 * s, + m.e12 * s, + m.e13 * s, + m.e21 * s, + m.e22 * s, + m.e23 * s, + m.e31 * s, + m.e32 * s, + m.e33 * s); +} + +inline Matrix3x3 operator*(float s, Matrix3x3 m) +{ + return Matrix3x3( m.e11 * s, + m.e12 * s, + m.e13 * s, + m.e21 * s, + m.e22 * s, + m.e23 * s, + m.e31 * s, + m.e32 * s, + m.e33 * s); +} + +inline Vector operator*(Matrix3x3 m, Vector u) +{ + return Vector( m.e11 * u.x + m.e12 * u.y + m.e13 * u.z, + m.e21 * u.x + m.e22 * u.y + m.e23 * u.z, + m.e31 * u.x + m.e32 * u.y + m.e33 * u.z); +} + +inline Vector operator*(Vector u, Matrix3x3 m) +{ + return Vector( u.x * m.e11 + u.y * m.e21 + u.z * m.e31, + u.x * m.e12 + u.y * m.e22 + u.z * m.e32, + u.x * m.e13 + u.y * m.e23 + u.z * m.e33); +} + +//------------------------------------------------------------------------// +// Quaternion Class and Quaternion functions +//------------------------------------------------------------------------// + +class Quaternion +{ +public: + float n; // number (scalar) part + Vector v; // vector part: v.x, v.y, v.z + + Quaternion(void); + Quaternion(float e0, float e1, float e2, float e3); + + float Magnitude(void); + Vector GetVector(void); + float GetScalar(void); + Quaternion operator+=(Quaternion q); + Quaternion operator-=(Quaternion q); + Quaternion operator*=(float s); + Quaternion operator/=(float s); + Quaternion operator~(void) const { + return Quaternion(n, -v.x, -v.y, -v.z); + } +}; + +inline Quaternion operator+(Quaternion q1, Quaternion q2); +inline Quaternion operator-(Quaternion q1, Quaternion q2); +inline Quaternion operator*(Quaternion q1, Quaternion q2); +inline Quaternion operator*(Quaternion q, float s); +inline Quaternion operator*(float s, Quaternion q); +inline Quaternion operator*(Quaternion q, Vector v); +inline Quaternion operator*(Vector v, Quaternion q); +inline Quaternion operator/(Quaternion q, float s); +inline float QGetAngle(Quaternion q); +inline Vector QGetAxis(Quaternion q); +inline Quaternion QRotate(Quaternion q1, Quaternion q2); +inline Vector QVRotate(Quaternion q, Vector v); +inline Quaternion MakeQFromEulerAngles(float x, float y, float z); +inline Vector MakeEulerAnglesFromQ(Quaternion q); + + +inline Quaternion::Quaternion(void) +{ + n = 0; + v.x = 0; + v.y = 0; + v.z = 0; +} + +inline Quaternion::Quaternion(float e0, float e1, float e2, float e3) +{ + n = e0; + v.x = e1; + v.y = e2; + v.z = e3; +} + +inline float Quaternion::Magnitude(void) +{ + return (float) sqrt(n * n + v.x * v.x + v.y * v.y + v.z * v.z); +} + +inline Vector Quaternion::GetVector(void) +{ + return Vector(v.x, v.y, v.z); +} + +inline float Quaternion::GetScalar(void) +{ + return n; +} + +inline Quaternion Quaternion::operator+=(Quaternion q) +{ + n += q.n; + v.x += q.v.x; + v.y += q.v.y; + v.z += q.v.z; + return *this; +} + +inline Quaternion Quaternion::operator-=(Quaternion q) +{ + n -= q.n; + v.x -= q.v.x; + v.y -= q.v.y; + v.z -= q.v.z; + return *this; +} + +inline Quaternion Quaternion::operator*=(float s) +{ + n *= s; + v.x *= s; + v.y *= s; + v.z *= s; + return *this; +} + +inline Quaternion Quaternion::operator/=(float s) +{ + n /= s; + v.x /= s; + v.y /= s; + v.z /= s; + return *this; +} + +/*inline Quaternion Quaternion::operator~() +{ +return Quaternion(n, -v.x, -v.y, -v.z); +}*/ + +inline Quaternion operator+(Quaternion q1, Quaternion q2) +{ + return Quaternion( q1.n + q2.n, + q1.v.x + q2.v.x, + q1.v.y + q2.v.y, + q1.v.z + q2.v.z); +} + +inline Quaternion operator-(Quaternion q1, Quaternion q2) +{ + return Quaternion( q1.n - q2.n, + q1.v.x - q2.v.x, + q1.v.y - q2.v.y, + q1.v.z - q2.v.z); +} + +inline Quaternion operator*(Quaternion q1, Quaternion q2) +{ + return Quaternion( q1.n * q2.n - q1.v.x * q2.v.x - q1.v.y * q2.v.y - q1.v.z * q2.v.z, + q1.n * q2.v.x + q1.v.x * q2.n + q1.v.y * q2.v.z - q1.v.z * q2.v.y, + q1.n * q2.v.y + q1.v.y * q2.n + q1.v.z * q2.v.x - q1.v.x * q2.v.z, + q1.n * q2.v.z + q1.v.z * q2.n + q1.v.x * q2.v.y - q1.v.y * q2.v.x); +} + +inline Quaternion operator*(Quaternion q, float s) +{ + return Quaternion(q.n * s, q.v.x * s, q.v.y * s, q.v.z * s); +} + +inline Quaternion operator*(float s, Quaternion q) +{ + return Quaternion(q.n * s, q.v.x * s, q.v.y * s, q.v.z * s); +} + +inline Quaternion operator*(Quaternion q, Vector v) +{ + return Quaternion( -(q.v.x * v.x + q.v.y * v.y + q.v.z * v.z), + q.n * v.x + q.v.y * v.z - q.v.z * v.y, + q.n * v.y + q.v.z * v.x - q.v.x * v.z, + q.n * v.z + q.v.x * v.y - q.v.y * v.x); +} + +inline Quaternion operator*(Vector v, Quaternion q) +{ + return Quaternion( -(q.v.x * v.x + q.v.y * v.y + q.v.z * v.z), + q.n * v.x + q.v.z * v.y - q.v.y * v.z, + q.n * v.y + q.v.x * v.z - q.v.z * v.x, + q.n * v.z + q.v.y * v.x - q.v.x * v.y); +} + +inline Quaternion operator/(Quaternion q, float s) +{ + return Quaternion(q.n / s, q.v.x / s, q.v.y / s, q.v.z / s); +} + +inline float QGetAngle(Quaternion q) +{ + return (float) (2 * acosf(q.n)); +} + +inline Vector QGetAxis(Quaternion q) +{ + Vector v; + float m; + + v = q.GetVector(); + m = v.Magnitude(); + + if (m <= tol) + return Vector(); + else + return v / m; +} + +inline Quaternion QRotate(Quaternion q1, Quaternion q2) +{ + return q1 * q2 * (~q1); +} + +inline Vector QVRotate(Quaternion q, Vector v) +{ + Quaternion t; + + + t = q * v * (~q); + + return t.GetVector(); +} + +inline Quaternion MakeQFromEulerAngles(float x, float y, float z) +{ + Quaternion q; + double roll = DegreesToRadians(x); + double pitch = DegreesToRadians(y); + double yaw = DegreesToRadians(z); + + double cyaw, cpitch, croll, syaw, spitch, sroll; + double cyawcpitch, syawspitch, cyawspitch, syawcpitch; + + cyaw = cos(0.5f * yaw); + cpitch = cos(0.5f * pitch); + croll = cos(0.5f * roll); + syaw = sin(0.5f * yaw); + spitch = sin(0.5f * pitch); + sroll = sin(0.5f * roll); + + cyawcpitch = cyaw * cpitch; + syawspitch = syaw * spitch; + cyawspitch = cyaw * spitch; + syawcpitch = syaw * cpitch; + + q.n = (float) (cyawcpitch * croll + syawspitch * sroll); + q.v.x = (float) (cyawcpitch * sroll - syawspitch * croll); + q.v.y = (float) (cyawspitch * croll + syawcpitch * sroll); + q.v.z = (float) (syawcpitch * croll - cyawspitch * sroll); + + return q; +} + +inline Vector MakeEulerAnglesFromQ(Quaternion q) +{ + double r11, r21, r31, r32, r33; + double q00, q11, q22, q33; + double tmp; + Vector u; + + q00 = q.n * q.n; + q11 = q.v.x * q.v.x; + q22 = q.v.y * q.v.y; + q33 = q.v.z * q.v.z; + + r11 = q00 + q11 - q22 - q33; + r21 = 2 * (q.v.x * q.v.y + q.n * q.v.z); + r31 = 2 * (q.v.x * q.v.z - q.n * q.v.y); + r32 = 2 * (q.v.y * q.v.z + q.n * q.v.x); + r33 = q00 - q11 - q22 + q33; + + tmp = fabs(r31); + if (tmp > 0.999999) { + double r12 = 2 * (q.v.x * q.v.y - q.n * q.v.z); + double r13 = 2 * (q.v.x * q.v.z + q.n * q.v.y); + + u.x = RadiansToDegrees(0.0f); //roll + u.y = RadiansToDegrees((float) (-(pi / 2) * r31 / tmp)); // pitch + u.z = RadiansToDegrees((float) atan2(-r12, -r31 * r13)); // yaw + return u; + } + + u.x = RadiansToDegrees((float) atan2(r32, r33)); // roll + u.y = RadiansToDegrees((float) asinf(-r31)); // pitch + u.z = RadiansToDegrees((float) atan2(r21, r11)); // yaw + return u; + + +} + + + + + +#endif diff --git a/Source/Math/Quaternions.cpp b/Source/Math/Quaternions.cpp index 7e68b97..0feaa70 100644 --- a/Source/Math/Quaternions.cpp +++ b/Source/Math/Quaternions.cpp @@ -18,7 +18,7 @@ You should have received a copy of the GNU General Public License along with Lugaru. If not, see . */ -#include "Math/Quaternions.h" +#include "Math/Quaternions.hpp" // Functions quaternion Quat_Mult(quaternion q1, quaternion q2) diff --git a/Source/Math/Quaternions.h b/Source/Math/Quaternions.h deleted file mode 100644 index de07302..0000000 --- a/Source/Math/Quaternions.h +++ /dev/null @@ -1,499 +0,0 @@ -/* -Copyright (C) 2003, 2010 - Wolfire Games -Copyright (C) 2010-2016 - Lugaru contributors (see AUTHORS file) - -This file is part of Lugaru. - -Lugaru is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2 of the License, or -(at your option) any later version. - -Lugaru is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with Lugaru. If not, see . -*/ - - -#ifndef _QUATERNIONS_H_ -#define _QUATERNIONS_H_ - -#include "math.h" -#include "PhysicsMath.h" -#include "Graphic/gamegl.h" - -/**> Quaternion Structures <**/ -#define PI 3.14159265355555897932384626 -#define RADIANS 0 -#define DEGREES 1 -#define deg2rad .0174532925 - -//using namespace std; -typedef float Matrix_t [4][4]; -struct euler { - float x, y, z; -}; -struct angle_axis { - float x, y, z, angle; -}; -struct quaternion { - float x, y, z, w; -}; - -class XYZ -{ -public: - float x; - float y; - float z; - XYZ() : x(0.0f), y(0.0f), z(0.0f) {} - inline XYZ operator+(XYZ add); - inline XYZ operator-(XYZ add); - inline XYZ operator*(float add); - inline XYZ operator*(XYZ add); - inline XYZ operator/(float add); - inline void operator+=(XYZ add); - inline void operator-=(XYZ add); - inline void operator*=(float add); - inline void operator*=(XYZ add); - inline void operator/=(float add); - inline void operator=(float add); - inline void vec(Vector add); - inline bool operator==(XYZ add); -}; - -/*********************> Quaternion Function definition <********/ -quaternion To_Quat(int Degree_Flag, euler Euler); -quaternion To_Quat(angle_axis Ang_Ax); -quaternion To_Quat(Matrix_t m); -angle_axis Quat_2_AA(quaternion Quat); -void Quat_2_Matrix(quaternion Quat, Matrix_t m); -quaternion Normalize(quaternion Quat); -quaternion Quat_Mult(quaternion q1, quaternion q2); -quaternion QNormalize(quaternion Quat); -XYZ Quat2Vector(quaternion Quat); - -inline void CrossProduct(XYZ *P, XYZ *Q, XYZ *V); -inline void CrossProduct(XYZ P, XYZ Q, XYZ *V); -inline void Normalise(XYZ *vectory); -inline float normaldotproduct(XYZ point1, XYZ point2); -inline float fast_sqrt (register float arg); -bool PointInTriangle(XYZ *p, XYZ normal, XYZ *p1, XYZ *p2, XYZ *p3); -bool LineFacet(XYZ p1, XYZ p2, XYZ pa, XYZ pb, XYZ pc, XYZ *p); -float LineFacetd(XYZ p1, XYZ p2, XYZ pa, XYZ pb, XYZ pc, XYZ *p); -float LineFacetd(XYZ p1, XYZ p2, XYZ pa, XYZ pb, XYZ pc, XYZ n, XYZ *p); -float LineFacetd(XYZ *p1, XYZ *p2, XYZ *pa, XYZ *pb, XYZ *pc, XYZ *n, XYZ *p); -float LineFacetd(XYZ *p1, XYZ *p2, XYZ *pa, XYZ *pb, XYZ *pc, XYZ *p); -bool PointInTriangle(Vector *p, Vector normal, float p11, float p12, float p13, float p21, float p22, float p23, float p31, float p32, float p33); -bool LineFacet(Vector p1, Vector p2, Vector pa, Vector pb, Vector pc, Vector *p); -inline void ReflectVector(XYZ *vel, const XYZ *n); -inline void ReflectVector(XYZ *vel, const XYZ &n); -inline XYZ DoRotation(XYZ thePoint, float xang, float yang, float zang); -inline XYZ DoRotationRadian(XYZ thePoint, float xang, float yang, float zang); -inline float findDistance(XYZ *point1, XYZ *point2); -inline float findLength(XYZ *point1); -inline float findLengthfast(XYZ *point1); -inline float distsq(XYZ *point1, XYZ *point2); -inline float distsq(XYZ point1, XYZ point2); -inline float distsqflat(XYZ *point1, XYZ *point2); -inline float dotproduct(const XYZ *point1, const XYZ *point2); -bool sphere_line_intersection ( - float x1, float y1 , float z1, - float x2, float y2 , float z2, - float x3, float y3 , float z3, float r ); -bool sphere_line_intersection ( - XYZ *p1, XYZ *p2, XYZ *p3, float *r ); -inline bool DistancePointLine( XYZ *Point, XYZ *LineStart, XYZ *LineEnd, float *Distance, XYZ *Intersection ); - - -inline void Normalise(XYZ *vectory) -{ - static float d; - d = fast_sqrt(vectory->x * vectory->x + vectory->y * vectory->y + vectory->z * vectory->z); - if (d == 0) { - return; - } - vectory->x /= d; - vectory->y /= d; - vectory->z /= d; -} - -inline XYZ XYZ::operator+(XYZ add) -{ - static XYZ ne; - ne = add; - ne.x += x; - ne.y += y; - ne.z += z; - return ne; -} - -inline XYZ XYZ::operator-(XYZ add) -{ - static XYZ ne; - ne = add; - ne.x = x - ne.x; - ne.y = y - ne.y; - ne.z = z - ne.z; - return ne; -} - -inline XYZ XYZ::operator*(float add) -{ - static XYZ ne; - ne.x = x * add; - ne.y = y * add; - ne.z = z * add; - return ne; -} - -inline XYZ XYZ::operator*(XYZ add) -{ - static XYZ ne; - ne.x = x * add.x; - ne.y = y * add.y; - ne.z = z * add.z; - return ne; -} - -inline XYZ XYZ::operator/(float add) -{ - static XYZ ne; - ne.x = x / add; - ne.y = y / add; - ne.z = z / add; - return ne; -} - -inline void XYZ::operator+=(XYZ add) -{ - x += add.x; - y += add.y; - z += add.z; -} - -inline void XYZ::operator-=(XYZ add) -{ - x = x - add.x; - y = y - add.y; - z = z - add.z; -} - -inline void XYZ::operator*=(float add) -{ - x = x * add; - y = y * add; - z = z * add; -} - -inline void XYZ::operator*=(XYZ add) -{ - x = x * add.x; - y = y * add.y; - z = z * add.z; -} - -inline void XYZ::operator/=(float add) -{ - x = x / add; - y = y / add; - z = z / add; -} - -inline void XYZ::operator=(float add) -{ - x = add; - y = add; - z = add; -} - -inline void XYZ::vec(Vector add) -{ - x = add.x; - y = add.y; - z = add.z; -} - -inline bool XYZ::operator==(XYZ add) -{ - if (x == add.x && y == add.y && z == add.z) - return 1; - return 0; -} - -inline void CrossProduct(XYZ *P, XYZ *Q, XYZ *V) -{ - V->x = P->y * Q->z - P->z * Q->y; - V->y = P->z * Q->x - P->x * Q->z; - V->z = P->x * Q->y - P->y * Q->x; -} - -inline void CrossProduct(XYZ P, XYZ Q, XYZ *V) -{ - V->x = P.y * Q.z - P.z * Q.y; - V->y = P.z * Q.x - P.x * Q.z; - V->z = P.x * Q.y - P.y * Q.x; -} - -inline float fast_sqrt (register float arg) -{ - return sqrtf(arg); -} - -inline float normaldotproduct(XYZ point1, XYZ point2) -{ - static GLfloat returnvalue; - Normalise(&point1); - Normalise(&point2); - returnvalue = (point1.x * point2.x + point1.y * point2.y + point1.z * point2.z); - return returnvalue; -} - -inline void ReflectVector(XYZ *vel, const XYZ *n) -{ - ReflectVector(vel, *n); -} - -inline void ReflectVector(XYZ *vel, const XYZ &n) -{ - static XYZ vn; - static XYZ vt; - static float dotprod; - - dotprod = dotproduct(&n, vel); - vn.x = n.x * dotprod; - vn.y = n.y * dotprod; - vn.z = n.z * dotprod; - - vt.x = vel->x - vn.x; - vt.y = vel->y - vn.y; - vt.z = vel->z - vn.z; - - vel->x = vt.x - vn.x; - vel->y = vt.y - vn.y; - vel->z = vt.z - vn.z; -} - -inline float dotproduct(const XYZ *point1, const XYZ *point2) -{ - static GLfloat returnvalue; - returnvalue = (point1->x * point2->x + point1->y * point2->y + point1->z * point2->z); - return returnvalue; -} - -inline float findDistance(XYZ *point1, XYZ *point2) -{ - return(fast_sqrt((point1->x - point2->x) * (point1->x - point2->x) + (point1->y - point2->y) * (point1->y - point2->y) + (point1->z - point2->z) * (point1->z - point2->z))); -} - -inline float findLength(XYZ *point1) -{ - return(fast_sqrt((point1->x) * (point1->x) + (point1->y) * (point1->y) + (point1->z) * (point1->z))); -} - - -inline float findLengthfast(XYZ *point1) -{ - return((point1->x) * (point1->x) + (point1->y) * (point1->y) + (point1->z) * (point1->z)); -} - -inline float distsq(XYZ *point1, XYZ *point2) -{ - return((point1->x - point2->x) * (point1->x - point2->x) + (point1->y - point2->y) * (point1->y - point2->y) + (point1->z - point2->z) * (point1->z - point2->z)); -} - -inline float distsq(XYZ point1, XYZ point2) -{ - return((point1.x - point2.x) * (point1.x - point2.x) + (point1.y - point2.y) * (point1.y - point2.y) + (point1.z - point2.z) * (point1.z - point2.z)); -} - -inline float distsqflat(XYZ *point1, XYZ *point2) -{ - return((point1->x - point2->x) * (point1->x - point2->x) + (point1->z - point2->z) * (point1->z - point2->z)); -} - -inline XYZ DoRotation(XYZ thePoint, float xang, float yang, float zang) -{ - static XYZ newpoint; - if (xang) { - xang *= 6.283185f; - xang /= 360; - } - if (yang) { - yang *= 6.283185f; - yang /= 360; - } - if (zang) { - zang *= 6.283185f; - zang /= 360; - } - - - if (yang) { - newpoint.z = thePoint.z * cosf(yang) - thePoint.x * sinf(yang); - newpoint.x = thePoint.z * sinf(yang) + thePoint.x * cosf(yang); - thePoint.z = newpoint.z; - thePoint.x = newpoint.x; - } - - if (zang) { - newpoint.x = thePoint.x * cosf(zang) - thePoint.y * sinf(zang); - newpoint.y = thePoint.y * cosf(zang) + thePoint.x * sinf(zang); - thePoint.x = newpoint.x; - thePoint.y = newpoint.y; - } - - if (xang) { - newpoint.y = thePoint.y * cosf(xang) - thePoint.z * sinf(xang); - newpoint.z = thePoint.y * sinf(xang) + thePoint.z * cosf(xang); - thePoint.z = newpoint.z; - thePoint.y = newpoint.y; - } - - return thePoint; -} - -inline float square( float f ) -{ - return (f * f) ; -} - -inline bool sphere_line_intersection ( - float x1, float y1 , float z1, - float x2, float y2 , float z2, - float x3, float y3 , float z3, float r ) -{ - - // x1,y1,z1 P1 coordinates (point of line) - // x2,y2,z2 P2 coordinates (point of line) - // x3,y3,z3, r P3 coordinates and radius (sphere) - // x,y,z intersection coordinates - // - // This function returns a pointer array which first index indicates - // the number of intersection point, followed by coordinate pairs. - - //~ static float x , y , z; - static float a, b, c, /*mu,*/ i ; - - if (x1 > x3 + r && x2 > x3 + r) return(0); - if (x1 < x3 - r && x2 < x3 - r) return(0); - if (y1 > y3 + r && y2 > y3 + r) return(0); - if (y1 < y3 - r && y2 < y3 - r) return(0); - if (z1 > z3 + r && z2 > z3 + r) return(0); - if (z1 < z3 - r && z2 < z3 - r) return(0); - a = square(x2 - x1) + square(y2 - y1) + square(z2 - z1); - b = 2 * ( (x2 - x1) * (x1 - x3) - + (y2 - y1) * (y1 - y3) - + (z2 - z1) * (z1 - z3) ) ; - c = square(x3) + square(y3) + - square(z3) + square(x1) + - square(y1) + square(z1) - - 2 * ( x3 * x1 + y3 * y1 + z3 * z1 ) - square(r) ; - i = b * b - 4 * a * c ; - - if ( i < 0.0 ) { - // no intersection - return(0); - } - return(1); -} - -inline bool sphere_line_intersection ( - XYZ *p1, XYZ *p2, XYZ *p3, float *r ) -{ - - // x1,p1->y,p1->z P1 coordinates (point of line) - // p2->x,p2->y,p2->z P2 coordinates (point of line) - // p3->x,p3->y,p3->z, r P3 coordinates and radius (sphere) - // x,y,z intersection coordinates - // - // This function returns a pointer array which first index indicates - // the number of intersection point, followed by coordinate pairs. - - //~ static float x , y , z; - static float a, b, c, /*mu,*/ i ; - - if (p1->x > p3->x + *r && p2->x > p3->x + *r) return(0); - if (p1->x < p3->x - *r && p2->x < p3->x - *r) return(0); - if (p1->y > p3->y + *r && p2->y > p3->y + *r) return(0); - if (p1->y < p3->y - *r && p2->y < p3->y - *r) return(0); - if (p1->z > p3->z + *r && p2->z > p3->z + *r) return(0); - if (p1->z < p3->z - *r && p2->z < p3->z - *r) return(0); - a = square(p2->x - p1->x) + square(p2->y - p1->y) + square(p2->z - p1->z); - b = 2 * ( (p2->x - p1->x) * (p1->x - p3->x) - + (p2->y - p1->y) * (p1->y - p3->y) - + (p2->z - p1->z) * (p1->z - p3->z) ) ; - c = square(p3->x) + square(p3->y) + - square(p3->z) + square(p1->x) + - square(p1->y) + square(p1->z) - - 2 * ( p3->x * p1->x + p3->y * p1->y + p3->z * p1->z ) - square(*r) ; - i = b * b - 4 * a * c ; - - if ( i < 0.0 ) { - // no intersection - return(0); - } - return(1); -} - -inline XYZ DoRotationRadian(XYZ thePoint, float xang, float yang, float zang) -{ - static XYZ newpoint; - static XYZ oldpoint; - - oldpoint = thePoint; - - if (yang != 0) { - newpoint.z = oldpoint.z * cosf(yang) - oldpoint.x * sinf(yang); - newpoint.x = oldpoint.z * sinf(yang) + oldpoint.x * cosf(yang); - oldpoint.z = newpoint.z; - oldpoint.x = newpoint.x; - } - - if (zang != 0) { - newpoint.x = oldpoint.x * cosf(zang) - oldpoint.y * sinf(zang); - newpoint.y = oldpoint.y * cosf(zang) + oldpoint.x * sinf(zang); - oldpoint.x = newpoint.x; - oldpoint.y = newpoint.y; - } - - if (xang != 0) { - newpoint.y = oldpoint.y * cosf(xang) - oldpoint.z * sinf(xang); - newpoint.z = oldpoint.y * sinf(xang) + oldpoint.z * cosf(xang); - oldpoint.z = newpoint.z; - oldpoint.y = newpoint.y; - } - - return oldpoint; - -} - -inline bool DistancePointLine( XYZ *Point, XYZ *LineStart, XYZ *LineEnd, float *Distance, XYZ *Intersection ) -{ - float LineMag; - float U; - - LineMag = findDistance( LineEnd, LineStart ); - - U = ( ( ( Point->x - LineStart->x ) * ( LineEnd->x - LineStart->x ) ) + - ( ( Point->y - LineStart->y ) * ( LineEnd->y - LineStart->y ) ) + - ( ( Point->z - LineStart->z ) * ( LineEnd->z - LineStart->z ) ) ) / - ( LineMag * LineMag ); - - if ( U < 0.0f || U > 1.0f ) - return 0; // closest point does not fall within the line segment - - Intersection->x = LineStart->x + U * ( LineEnd->x - LineStart->x ); - Intersection->y = LineStart->y + U * ( LineEnd->y - LineStart->y ); - Intersection->z = LineStart->z + U * ( LineEnd->z - LineStart->z ); - - *Distance = findDistance( Point, Intersection ); - - return 1; -} - -#endif diff --git a/Source/Math/Quaternions.hpp b/Source/Math/Quaternions.hpp new file mode 100644 index 0000000..3220545 --- /dev/null +++ b/Source/Math/Quaternions.hpp @@ -0,0 +1,499 @@ +/* +Copyright (C) 2003, 2010 - Wolfire Games +Copyright (C) 2010-2016 - Lugaru contributors (see AUTHORS file) + +This file is part of Lugaru. + +Lugaru is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +Lugaru is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with Lugaru. If not, see . +*/ + +#ifndef _QUATERNIONS_HPP_ +#define _QUATERNIONS_HPP_ + +#include "PhysicsMath.hpp" +#include "Graphic/gamegl.hpp" + +#include + +/**> Quaternion Structures <**/ +#define PI 3.14159265355555897932384626 +#define RADIANS 0 +#define DEGREES 1 +#define deg2rad .0174532925 + +//using namespace std; +typedef float Matrix_t [4][4]; +struct euler { + float x, y, z; +}; +struct angle_axis { + float x, y, z, angle; +}; +struct quaternion { + float x, y, z, w; +}; + +class XYZ +{ +public: + float x; + float y; + float z; + XYZ() : x(0.0f), y(0.0f), z(0.0f) {} + inline XYZ operator+(XYZ add); + inline XYZ operator-(XYZ add); + inline XYZ operator*(float add); + inline XYZ operator*(XYZ add); + inline XYZ operator/(float add); + inline void operator+=(XYZ add); + inline void operator-=(XYZ add); + inline void operator*=(float add); + inline void operator*=(XYZ add); + inline void operator/=(float add); + inline void operator=(float add); + inline void vec(Vector add); + inline bool operator==(XYZ add); +}; + +/*********************> Quaternion Function definition <********/ +quaternion To_Quat(int Degree_Flag, euler Euler); +quaternion To_Quat(angle_axis Ang_Ax); +quaternion To_Quat(Matrix_t m); +angle_axis Quat_2_AA(quaternion Quat); +void Quat_2_Matrix(quaternion Quat, Matrix_t m); +quaternion Normalize(quaternion Quat); +quaternion Quat_Mult(quaternion q1, quaternion q2); +quaternion QNormalize(quaternion Quat); +XYZ Quat2Vector(quaternion Quat); + +inline void CrossProduct(XYZ *P, XYZ *Q, XYZ *V); +inline void CrossProduct(XYZ P, XYZ Q, XYZ *V); +inline void Normalise(XYZ *vectory); +inline float normaldotproduct(XYZ point1, XYZ point2); +inline float fast_sqrt (register float arg); +bool PointInTriangle(XYZ *p, XYZ normal, XYZ *p1, XYZ *p2, XYZ *p3); +bool LineFacet(XYZ p1, XYZ p2, XYZ pa, XYZ pb, XYZ pc, XYZ *p); +float LineFacetd(XYZ p1, XYZ p2, XYZ pa, XYZ pb, XYZ pc, XYZ *p); +float LineFacetd(XYZ p1, XYZ p2, XYZ pa, XYZ pb, XYZ pc, XYZ n, XYZ *p); +float LineFacetd(XYZ *p1, XYZ *p2, XYZ *pa, XYZ *pb, XYZ *pc, XYZ *n, XYZ *p); +float LineFacetd(XYZ *p1, XYZ *p2, XYZ *pa, XYZ *pb, XYZ *pc, XYZ *p); +bool PointInTriangle(Vector *p, Vector normal, float p11, float p12, float p13, float p21, float p22, float p23, float p31, float p32, float p33); +bool LineFacet(Vector p1, Vector p2, Vector pa, Vector pb, Vector pc, Vector *p); +inline void ReflectVector(XYZ *vel, const XYZ *n); +inline void ReflectVector(XYZ *vel, const XYZ &n); +inline XYZ DoRotation(XYZ thePoint, float xang, float yang, float zang); +inline XYZ DoRotationRadian(XYZ thePoint, float xang, float yang, float zang); +inline float findDistance(XYZ *point1, XYZ *point2); +inline float findLength(XYZ *point1); +inline float findLengthfast(XYZ *point1); +inline float distsq(XYZ *point1, XYZ *point2); +inline float distsq(XYZ point1, XYZ point2); +inline float distsqflat(XYZ *point1, XYZ *point2); +inline float dotproduct(const XYZ *point1, const XYZ *point2); +bool sphere_line_intersection ( + float x1, float y1 , float z1, + float x2, float y2 , float z2, + float x3, float y3 , float z3, float r ); +bool sphere_line_intersection ( + XYZ *p1, XYZ *p2, XYZ *p3, float *r ); +inline bool DistancePointLine( XYZ *Point, XYZ *LineStart, XYZ *LineEnd, float *Distance, XYZ *Intersection ); + + +inline void Normalise(XYZ *vectory) +{ + static float d; + d = fast_sqrt(vectory->x * vectory->x + vectory->y * vectory->y + vectory->z * vectory->z); + if (d == 0) { + return; + } + vectory->x /= d; + vectory->y /= d; + vectory->z /= d; +} + +inline XYZ XYZ::operator+(XYZ add) +{ + static XYZ ne; + ne = add; + ne.x += x; + ne.y += y; + ne.z += z; + return ne; +} + +inline XYZ XYZ::operator-(XYZ add) +{ + static XYZ ne; + ne = add; + ne.x = x - ne.x; + ne.y = y - ne.y; + ne.z = z - ne.z; + return ne; +} + +inline XYZ XYZ::operator*(float add) +{ + static XYZ ne; + ne.x = x * add; + ne.y = y * add; + ne.z = z * add; + return ne; +} + +inline XYZ XYZ::operator*(XYZ add) +{ + static XYZ ne; + ne.x = x * add.x; + ne.y = y * add.y; + ne.z = z * add.z; + return ne; +} + +inline XYZ XYZ::operator/(float add) +{ + static XYZ ne; + ne.x = x / add; + ne.y = y / add; + ne.z = z / add; + return ne; +} + +inline void XYZ::operator+=(XYZ add) +{ + x += add.x; + y += add.y; + z += add.z; +} + +inline void XYZ::operator-=(XYZ add) +{ + x = x - add.x; + y = y - add.y; + z = z - add.z; +} + +inline void XYZ::operator*=(float add) +{ + x = x * add; + y = y * add; + z = z * add; +} + +inline void XYZ::operator*=(XYZ add) +{ + x = x * add.x; + y = y * add.y; + z = z * add.z; +} + +inline void XYZ::operator/=(float add) +{ + x = x / add; + y = y / add; + z = z / add; +} + +inline void XYZ::operator=(float add) +{ + x = add; + y = add; + z = add; +} + +inline void XYZ::vec(Vector add) +{ + x = add.x; + y = add.y; + z = add.z; +} + +inline bool XYZ::operator==(XYZ add) +{ + if (x == add.x && y == add.y && z == add.z) + return 1; + return 0; +} + +inline void CrossProduct(XYZ *P, XYZ *Q, XYZ *V) +{ + V->x = P->y * Q->z - P->z * Q->y; + V->y = P->z * Q->x - P->x * Q->z; + V->z = P->x * Q->y - P->y * Q->x; +} + +inline void CrossProduct(XYZ P, XYZ Q, XYZ *V) +{ + V->x = P.y * Q.z - P.z * Q.y; + V->y = P.z * Q.x - P.x * Q.z; + V->z = P.x * Q.y - P.y * Q.x; +} + +inline float fast_sqrt (register float arg) +{ + return sqrtf(arg); +} + +inline float normaldotproduct(XYZ point1, XYZ point2) +{ + static GLfloat returnvalue; + Normalise(&point1); + Normalise(&point2); + returnvalue = (point1.x * point2.x + point1.y * point2.y + point1.z * point2.z); + return returnvalue; +} + +inline void ReflectVector(XYZ *vel, const XYZ *n) +{ + ReflectVector(vel, *n); +} + +inline void ReflectVector(XYZ *vel, const XYZ &n) +{ + static XYZ vn; + static XYZ vt; + static float dotprod; + + dotprod = dotproduct(&n, vel); + vn.x = n.x * dotprod; + vn.y = n.y * dotprod; + vn.z = n.z * dotprod; + + vt.x = vel->x - vn.x; + vt.y = vel->y - vn.y; + vt.z = vel->z - vn.z; + + vel->x = vt.x - vn.x; + vel->y = vt.y - vn.y; + vel->z = vt.z - vn.z; +} + +inline float dotproduct(const XYZ *point1, const XYZ *point2) +{ + static GLfloat returnvalue; + returnvalue = (point1->x * point2->x + point1->y * point2->y + point1->z * point2->z); + return returnvalue; +} + +inline float findDistance(XYZ *point1, XYZ *point2) +{ + return(fast_sqrt((point1->x - point2->x) * (point1->x - point2->x) + (point1->y - point2->y) * (point1->y - point2->y) + (point1->z - point2->z) * (point1->z - point2->z))); +} + +inline float findLength(XYZ *point1) +{ + return(fast_sqrt((point1->x) * (point1->x) + (point1->y) * (point1->y) + (point1->z) * (point1->z))); +} + + +inline float findLengthfast(XYZ *point1) +{ + return((point1->x) * (point1->x) + (point1->y) * (point1->y) + (point1->z) * (point1->z)); +} + +inline float distsq(XYZ *point1, XYZ *point2) +{ + return((point1->x - point2->x) * (point1->x - point2->x) + (point1->y - point2->y) * (point1->y - point2->y) + (point1->z - point2->z) * (point1->z - point2->z)); +} + +inline float distsq(XYZ point1, XYZ point2) +{ + return((point1.x - point2.x) * (point1.x - point2.x) + (point1.y - point2.y) * (point1.y - point2.y) + (point1.z - point2.z) * (point1.z - point2.z)); +} + +inline float distsqflat(XYZ *point1, XYZ *point2) +{ + return((point1->x - point2->x) * (point1->x - point2->x) + (point1->z - point2->z) * (point1->z - point2->z)); +} + +inline XYZ DoRotation(XYZ thePoint, float xang, float yang, float zang) +{ + static XYZ newpoint; + if (xang) { + xang *= 6.283185f; + xang /= 360; + } + if (yang) { + yang *= 6.283185f; + yang /= 360; + } + if (zang) { + zang *= 6.283185f; + zang /= 360; + } + + + if (yang) { + newpoint.z = thePoint.z * cosf(yang) - thePoint.x * sinf(yang); + newpoint.x = thePoint.z * sinf(yang) + thePoint.x * cosf(yang); + thePoint.z = newpoint.z; + thePoint.x = newpoint.x; + } + + if (zang) { + newpoint.x = thePoint.x * cosf(zang) - thePoint.y * sinf(zang); + newpoint.y = thePoint.y * cosf(zang) + thePoint.x * sinf(zang); + thePoint.x = newpoint.x; + thePoint.y = newpoint.y; + } + + if (xang) { + newpoint.y = thePoint.y * cosf(xang) - thePoint.z * sinf(xang); + newpoint.z = thePoint.y * sinf(xang) + thePoint.z * cosf(xang); + thePoint.z = newpoint.z; + thePoint.y = newpoint.y; + } + + return thePoint; +} + +inline float square( float f ) +{ + return (f * f) ; +} + +inline bool sphere_line_intersection ( + float x1, float y1 , float z1, + float x2, float y2 , float z2, + float x3, float y3 , float z3, float r ) +{ + + // x1,y1,z1 P1 coordinates (point of line) + // x2,y2,z2 P2 coordinates (point of line) + // x3,y3,z3, r P3 coordinates and radius (sphere) + // x,y,z intersection coordinates + // + // This function returns a pointer array which first index indicates + // the number of intersection point, followed by coordinate pairs. + + //~ static float x , y , z; + static float a, b, c, /*mu,*/ i ; + + if (x1 > x3 + r && x2 > x3 + r) return(0); + if (x1 < x3 - r && x2 < x3 - r) return(0); + if (y1 > y3 + r && y2 > y3 + r) return(0); + if (y1 < y3 - r && y2 < y3 - r) return(0); + if (z1 > z3 + r && z2 > z3 + r) return(0); + if (z1 < z3 - r && z2 < z3 - r) return(0); + a = square(x2 - x1) + square(y2 - y1) + square(z2 - z1); + b = 2 * ( (x2 - x1) * (x1 - x3) + + (y2 - y1) * (y1 - y3) + + (z2 - z1) * (z1 - z3) ) ; + c = square(x3) + square(y3) + + square(z3) + square(x1) + + square(y1) + square(z1) - + 2 * ( x3 * x1 + y3 * y1 + z3 * z1 ) - square(r) ; + i = b * b - 4 * a * c ; + + if ( i < 0.0 ) { + // no intersection + return(0); + } + return(1); +} + +inline bool sphere_line_intersection ( + XYZ *p1, XYZ *p2, XYZ *p3, float *r ) +{ + + // x1,p1->y,p1->z P1 coordinates (point of line) + // p2->x,p2->y,p2->z P2 coordinates (point of line) + // p3->x,p3->y,p3->z, r P3 coordinates and radius (sphere) + // x,y,z intersection coordinates + // + // This function returns a pointer array which first index indicates + // the number of intersection point, followed by coordinate pairs. + + //~ static float x , y , z; + static float a, b, c, /*mu,*/ i ; + + if (p1->x > p3->x + *r && p2->x > p3->x + *r) return(0); + if (p1->x < p3->x - *r && p2->x < p3->x - *r) return(0); + if (p1->y > p3->y + *r && p2->y > p3->y + *r) return(0); + if (p1->y < p3->y - *r && p2->y < p3->y - *r) return(0); + if (p1->z > p3->z + *r && p2->z > p3->z + *r) return(0); + if (p1->z < p3->z - *r && p2->z < p3->z - *r) return(0); + a = square(p2->x - p1->x) + square(p2->y - p1->y) + square(p2->z - p1->z); + b = 2 * ( (p2->x - p1->x) * (p1->x - p3->x) + + (p2->y - p1->y) * (p1->y - p3->y) + + (p2->z - p1->z) * (p1->z - p3->z) ) ; + c = square(p3->x) + square(p3->y) + + square(p3->z) + square(p1->x) + + square(p1->y) + square(p1->z) - + 2 * ( p3->x * p1->x + p3->y * p1->y + p3->z * p1->z ) - square(*r) ; + i = b * b - 4 * a * c ; + + if ( i < 0.0 ) { + // no intersection + return(0); + } + return(1); +} + +inline XYZ DoRotationRadian(XYZ thePoint, float xang, float yang, float zang) +{ + static XYZ newpoint; + static XYZ oldpoint; + + oldpoint = thePoint; + + if (yang != 0) { + newpoint.z = oldpoint.z * cosf(yang) - oldpoint.x * sinf(yang); + newpoint.x = oldpoint.z * sinf(yang) + oldpoint.x * cosf(yang); + oldpoint.z = newpoint.z; + oldpoint.x = newpoint.x; + } + + if (zang != 0) { + newpoint.x = oldpoint.x * cosf(zang) - oldpoint.y * sinf(zang); + newpoint.y = oldpoint.y * cosf(zang) + oldpoint.x * sinf(zang); + oldpoint.x = newpoint.x; + oldpoint.y = newpoint.y; + } + + if (xang != 0) { + newpoint.y = oldpoint.y * cosf(xang) - oldpoint.z * sinf(xang); + newpoint.z = oldpoint.y * sinf(xang) + oldpoint.z * cosf(xang); + oldpoint.z = newpoint.z; + oldpoint.y = newpoint.y; + } + + return oldpoint; + +} + +inline bool DistancePointLine( XYZ *Point, XYZ *LineStart, XYZ *LineEnd, float *Distance, XYZ *Intersection ) +{ + float LineMag; + float U; + + LineMag = findDistance( LineEnd, LineStart ); + + U = ( ( ( Point->x - LineStart->x ) * ( LineEnd->x - LineStart->x ) ) + + ( ( Point->y - LineStart->y ) * ( LineEnd->y - LineStart->y ) ) + + ( ( Point->z - LineStart->z ) * ( LineEnd->z - LineStart->z ) ) ) / + ( LineMag * LineMag ); + + if ( U < 0.0f || U > 1.0f ) + return 0; // closest point does not fall within the line segment + + Intersection->x = LineStart->x + U * ( LineEnd->x - LineStart->x ); + Intersection->y = LineStart->y + U * ( LineEnd->y - LineStart->y ); + Intersection->z = LineStart->z + U * ( LineEnd->z - LineStart->z ); + + *Distance = findDistance( Point, Intersection ); + + return 1; +} + +#endif diff --git a/Source/Math/Random.h b/Source/Math/Random.h deleted file mode 100644 index 096cedc..0000000 --- a/Source/Math/Random.h +++ /dev/null @@ -1,31 +0,0 @@ -/* -Copyright (C) 2003, 2010 - Wolfire Games -Copyright (C) 2010-2016 - Lugaru contributors (see AUTHORS file) - -This file is part of Lugaru. - -Lugaru is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2 of the License, or -(at your option) any later version. - -Lugaru is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with Lugaru. If not, see . -*/ - -#ifndef _RANDOM_H_ -#define _RANDOM_H_ - -#include - -static inline short Random() -{ - return rand(); -} - -#endif diff --git a/Source/Math/Random.hpp b/Source/Math/Random.hpp new file mode 100644 index 0000000..430023c --- /dev/null +++ b/Source/Math/Random.hpp @@ -0,0 +1,31 @@ +/* +Copyright (C) 2003, 2010 - Wolfire Games +Copyright (C) 2010-2016 - Lugaru contributors (see AUTHORS file) + +This file is part of Lugaru. + +Lugaru is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +Lugaru is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with Lugaru. If not, see . +*/ + +#ifndef _RANDOM_HPP_ +#define _RANDOM_HPP_ + +#include + +static inline short Random() +{ + return rand(); +} + +#endif diff --git a/Source/Menu/Menu.cpp b/Source/Menu/Menu.cpp index 3639740..7d8bce8 100644 --- a/Source/Menu/Menu.cpp +++ b/Source/Menu/Menu.cpp @@ -18,19 +18,20 @@ You should have received a copy of the GNU General Public License along with Lugaru. If not, see . */ -#include -#include -#include +#include "Menu/Menu.hpp" -#include "Graphic/gamegl.h" -#include "Level/Campaign.h" -#include "Menu/Menu.h" -#include "User/Settings.h" -#include "Utils/Input.h" +#include "Audio/openal_wrapper.hpp" +#include "Graphic/gamegl.hpp" +#include "Level/Campaign.hpp" +#include "User/Settings.hpp" +#include "Utils/Input.hpp" // Should not be needed, Menu should call methods from other classes to launch maps and challenges and so on -#include "Level/Awards.h" -#include "Audio/openal_wrapper.h" +#include "Level/Awards.hpp" + +#include +#include +#include using namespace Game; diff --git a/Source/Menu/Menu.h b/Source/Menu/Menu.h deleted file mode 100644 index bf99bdc..0000000 --- a/Source/Menu/Menu.h +++ /dev/null @@ -1,72 +0,0 @@ -/* -Copyright (C) 2003, 2010 - Wolfire Games -Copyright (C) 2010-2016 - Lugaru contributors (see AUTHORS file) - -This file is part of Lugaru. - -Lugaru is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2 of the License, or -(at your option) any later version. - -Lugaru is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with Lugaru. If not, see . -*/ - -#ifndef _MENU_H_ -#define _MENU_H_ - -#include "Game.h" - -struct MenuItem { - enum MenuItemType {NONE, LABEL, BUTTON, IMAGE, IMAGEBUTTON, MAPMARKER, MAPLINE, MAPLABEL} type; - int id; - string text; - Texture texture; - int x, y, w, h; - float r, g, b; - float effectfade; - - float linestartsize; - float lineendsize; - - MenuItem(MenuItemType _type, int _id, const string& _text, Texture _texture, - int _x, int _y, int _w, int _h, float _r, float _g, float _b, - float _linestartsize = 1, float _lineendsize = 1); -}; - -class Menu -{ -public: - static void clearMenu(); - static void addLabel(int id, const string& text, int x, int y, float r = 1, float g = 0, float b = 0); - static void addButton(int id, const string& text, int x, int y, float r = 1, float g = 0, float b = 0); - static void addImage(int id, Texture texture, int x, int y, int w, int h, float r = 1, float g = 1, float b = 1); - static void addButtonImage(int id, Texture texture, int x, int y, int w, int h, float r = 1, float g = 1, float b = 1); - static void addMapLine(int x, int y, int w, int h, float startsize, float endsize, float r, float g, float b); - static void addMapMarker(int id, Texture texture, int x, int y, int w, int h, float r, float g, float b); - static void addMapLabel(int id, const string& text, int x, int y, float r = 1, float g = 0, float b = 0); - static void setText(int id, const string& text); - static void setText(int id, const string& text, int x, int y, int w, int h); - static int getSelected(int mousex, int mousey); - static void drawItems(); - - static void Load(); - static void Tick(); - static void updateSettingsMenu(); - static void updateStereoConfigMenu(); - static void updateControlsMenu(); - static void setKeySelected(); - -private: - static void handleFadeEffect(); - - static std::vector items; -}; - -#endif diff --git a/Source/Menu/Menu.hpp b/Source/Menu/Menu.hpp new file mode 100644 index 0000000..eea5a5c --- /dev/null +++ b/Source/Menu/Menu.hpp @@ -0,0 +1,72 @@ +/* +Copyright (C) 2003, 2010 - Wolfire Games +Copyright (C) 2010-2016 - Lugaru contributors (see AUTHORS file) + +This file is part of Lugaru. + +Lugaru is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +Lugaru is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with Lugaru. If not, see . +*/ + +#ifndef _MENU_HPP_ +#define _MENU_HPP_ + +#include "Game.hpp" + +struct MenuItem { + enum MenuItemType {NONE, LABEL, BUTTON, IMAGE, IMAGEBUTTON, MAPMARKER, MAPLINE, MAPLABEL} type; + int id; + string text; + Texture texture; + int x, y, w, h; + float r, g, b; + float effectfade; + + float linestartsize; + float lineendsize; + + MenuItem(MenuItemType _type, int _id, const string& _text, Texture _texture, + int _x, int _y, int _w, int _h, float _r, float _g, float _b, + float _linestartsize = 1, float _lineendsize = 1); +}; + +class Menu +{ +public: + static void clearMenu(); + static void addLabel(int id, const string& text, int x, int y, float r = 1, float g = 0, float b = 0); + static void addButton(int id, const string& text, int x, int y, float r = 1, float g = 0, float b = 0); + static void addImage(int id, Texture texture, int x, int y, int w, int h, float r = 1, float g = 1, float b = 1); + static void addButtonImage(int id, Texture texture, int x, int y, int w, int h, float r = 1, float g = 1, float b = 1); + static void addMapLine(int x, int y, int w, int h, float startsize, float endsize, float r, float g, float b); + static void addMapMarker(int id, Texture texture, int x, int y, int w, int h, float r, float g, float b); + static void addMapLabel(int id, const string& text, int x, int y, float r = 1, float g = 0, float b = 0); + static void setText(int id, const string& text); + static void setText(int id, const string& text, int x, int y, int w, int h); + static int getSelected(int mousex, int mousey); + static void drawItems(); + + static void Load(); + static void Tick(); + static void updateSettingsMenu(); + static void updateStereoConfigMenu(); + static void updateControlsMenu(); + static void setKeySelected(); + +private: + static void handleFadeEffect(); + + static std::vector items; +}; + +#endif diff --git a/Source/Objects/Objects.cpp b/Source/Objects/Objects.cpp index 20e117c..9064ff8 100644 --- a/Source/Objects/Objects.cpp +++ b/Source/Objects/Objects.cpp @@ -18,7 +18,7 @@ You should have received a copy of the GNU General Public License along with Lugaru. If not, see . */ -#include "Objects/Objects.h" +#include "Objects/Objects.hpp" extern XYZ viewer; extern float viewdistance; diff --git a/Source/Objects/Objects.h b/Source/Objects/Objects.h deleted file mode 100644 index 83f17c2..0000000 --- a/Source/Objects/Objects.h +++ /dev/null @@ -1,101 +0,0 @@ -/* -Copyright (C) 2003, 2010 - Wolfire Games -Copyright (C) 2010-2016 - Lugaru contributors (see AUTHORS file) - -This file is part of Lugaru. - -Lugaru is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2 of the License, or -(at your option) any later version. - -Lugaru is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with Lugaru. If not, see . -*/ - -#ifndef _OBJECTS_H_ -#define _OBJECTS_H_ - -#include "Environment/Lights.h" -#include "Environment/Terrain.h" -#include "Graphic/gamegl.h" -#include "Graphic/Models.h" -#include "Graphic/Sprite.h" -#include "Graphic/Texture.h" -#include "Math/Frustum.h" -#include "Math/Quaternions.h" -#include "Math/Quaternions.h" -#include "Utils/ImageIO.h" - -#include -// -// Model Structures -// - -#define max_objects 300 - -#define boxtype 0 -#define weirdtype 1 -#define spiketype 2 -#define treetrunktype 3 -#define treeleavestype 4 -#define bushtype 5 -#define rocktype 6 -#define walltype 7 -#define chimneytype 8 -#define platformtype 9 -#define tunneltype 11 -#define cooltype 12 -#define firetype 13 - - -class Objects -{ -public: - XYZ center; - float radius; - XYZ position[max_objects]; - int type[max_objects]; - float yaw[max_objects]; - float pitch[max_objects]; - float rotx[max_objects]; - float rotxvel[max_objects]; - float roty[max_objects]; - float rotyvel[max_objects]; - int numobjects; - bool possible[max_objects]; - Model model[max_objects]; - Model displaymodel[max_objects]; - float friction[max_objects]; - float scale[max_objects]; - float messedwith[max_objects]; - float checked[max_objects]; - Texture boxtextureptr; - Texture treetextureptr; - Texture bushtextureptr; - Texture rocktextureptr; - float shadowed[max_objects]; - float occluded[max_objects]; - bool checkcollide(XYZ startpoint, XYZ endpoint, int which); - bool onfire[max_objects]; - float flamedelay[max_objects]; - - void SphereCheckPossible(XYZ *p1, float radius); - void DeleteObject(int which); - void MakeObject(int atype, XYZ where, float ayaw, float ascale); - void MakeObject(int atype, XYZ where, float ayaw, float apitch, float ascale); - void Draw(); - void DoShadows(); - void DoStuff(); - - Objects(); - ~Objects(); -}; - -#endif - diff --git a/Source/Objects/Objects.hpp b/Source/Objects/Objects.hpp new file mode 100644 index 0000000..70f382a --- /dev/null +++ b/Source/Objects/Objects.hpp @@ -0,0 +1,100 @@ +/* +Copyright (C) 2003, 2010 - Wolfire Games +Copyright (C) 2010-2016 - Lugaru contributors (see AUTHORS file) + +This file is part of Lugaru. + +Lugaru is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +Lugaru is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with Lugaru. If not, see . +*/ + +#ifndef _OBJECTS_HPP_ +#define _OBJECTS_HPP_ + +#include "Environment/Lights.hpp" +#include "Environment/Terrain.hpp" +#include "Graphic/gamegl.hpp" +#include "Graphic/Models.hpp" +#include "Graphic/Sprite.hpp" +#include "Graphic/Texture.hpp" +#include "Math/Frustum.hpp" +#include "Math/Quaternions.hpp" +#include "Utils/ImageIO.hpp" + +#include +// +// Model Structures +// + +#define max_objects 300 + +#define boxtype 0 +#define weirdtype 1 +#define spiketype 2 +#define treetrunktype 3 +#define treeleavestype 4 +#define bushtype 5 +#define rocktype 6 +#define walltype 7 +#define chimneytype 8 +#define platformtype 9 +#define tunneltype 11 +#define cooltype 12 +#define firetype 13 + + +class Objects +{ +public: + XYZ center; + float radius; + XYZ position[max_objects]; + int type[max_objects]; + float yaw[max_objects]; + float pitch[max_objects]; + float rotx[max_objects]; + float rotxvel[max_objects]; + float roty[max_objects]; + float rotyvel[max_objects]; + int numobjects; + bool possible[max_objects]; + Model model[max_objects]; + Model displaymodel[max_objects]; + float friction[max_objects]; + float scale[max_objects]; + float messedwith[max_objects]; + float checked[max_objects]; + Texture boxtextureptr; + Texture treetextureptr; + Texture bushtextureptr; + Texture rocktextureptr; + float shadowed[max_objects]; + float occluded[max_objects]; + bool checkcollide(XYZ startpoint, XYZ endpoint, int which); + bool onfire[max_objects]; + float flamedelay[max_objects]; + + void SphereCheckPossible(XYZ *p1, float radius); + void DeleteObject(int which); + void MakeObject(int atype, XYZ where, float ayaw, float ascale); + void MakeObject(int atype, XYZ where, float ayaw, float apitch, float ascale); + void Draw(); + void DoShadows(); + void DoStuff(); + + Objects(); + ~Objects(); +}; + +#endif + diff --git a/Source/Objects/Person.cpp b/Source/Objects/Person.cpp index c1eb88d..8181e81 100644 --- a/Source/Objects/Person.cpp +++ b/Source/Objects/Person.cpp @@ -18,16 +18,15 @@ You should have received a copy of the GNU General Public License along with Lugaru. If not, see . */ -/**> HEADER FILES <**/ -#include "Animation/Animation.h" -#include "Audio/openal_wrapper.h" -#include "Audio/Sounds.h" -#include "Level/Awards.h" -#include "Level/Dialog.h" -#include "Objects/Person.h" -#include "Utils/Folders.h" - -#include "Game.h" +#include "Objects/Person.hpp" + +#include "Animation/Animation.hpp" +#include "Audio/openal_wrapper.hpp" +#include "Audio/Sounds.hpp" +#include "Game.hpp" +#include "Level/Awards.hpp" +#include "Level/Dialog.hpp" +#include "Utils/Folders.hpp" extern float multiplier; extern Terrain terrain; diff --git a/Source/Objects/Person.h b/Source/Objects/Person.h deleted file mode 100644 index 4fa115f..0000000 --- a/Source/Objects/Person.h +++ /dev/null @@ -1,403 +0,0 @@ -/* -Copyright (C) 2003, 2010 - Wolfire Games -Copyright (C) 2010-2016 - Lugaru contributors (see AUTHORS file) - -This file is part of Lugaru. - -Lugaru is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2 of the License, or -(at your option) any later version. - -Lugaru is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with Lugaru. If not, see . -*/ - -#ifndef _PERSON_H_ -#define _PERSON_H_ - -/**> HEADER FILES <**/ -#include "Animation/Animation.h" -#include "Animation/Skeleton.h" -#include "Environment/Terrain.h" -#include "Graphic/gamegl.h" -#include "Graphic/Models.h" -#include "Graphic/Sprite.h" -#include "Math/Quaternions.h" -#include "Objects/Weapons.h" - -#include -#include - -#define passivetype 0 -#define guardtype 1 -#define searchtype 2 -#define attacktype 3 -#define attacktypecutoff 4 -#define playercontrolled 5 -#define gethelptype 6 -#define getweapontype 7 -#define pathfindtype 8 - -#define rabbittype 0 -#define wolftype 1 - -struct InvalidPersonException : public exception { - const char * what () const throw () { - return "Invalid weapon number"; - } -}; - -class Person : public enable_shared_from_this -{ -public: - static std::vector> players; - - int whichpatchx; - int whichpatchz; - - // animCurrent and animTarget are used to interpolate between different animations - // (and for a bunch of other things). - // animations interpolate with one another at various speeds. - // animTarget seems to determine the combat state? - int animCurrent; - int animTarget; - - // frameCurrent and frameTarget are used to interpolate between the frames of an animation - // (e.g. the crouched animation has only two frames, lerped back and forth slowly). - // animations advance at various speeds. - int frameCurrent; - int frameTarget; - - int oldanimCurrent; - int oldanimTarget; - int oldframeCurrent; - int oldframeTarget; - - int howactive; - - float parriedrecently; - - bool superruntoggle; - - int lastattack, lastattack2, lastattack3; - - XYZ currentoffset, targetoffset, offset; - float target; - float transspeed; - - XYZ realoldcoords; - XYZ oldcoords; - XYZ coords; - XYZ velocity; - - XYZ proportionhead; - XYZ proportionlegs; - XYZ proportionarms; - XYZ proportionbody; - - float unconscioustime; - - bool immobile; - - float velspeed; - float targetyaw; - float targetrot; - float rot; - float oldrot; - float lookyaw; - float lookpitch; - float yaw; - float pitch; - float lowyaw; - float tilt; - float targettilt; - float tilt2; - float targettilt2; - bool rabbitkickenabled; - - float bloodloss; - float bleeddelay; - float skiddelay; - float skiddingdelay; - float deathbleeding; - float tempdeltav; - - float damagetolerance; - float damage; - float permanentdamage; - float superpermanentdamage; - float lastcollide; - /* Seems to be 0 = alive, 1 = unconscious, 2 = dead */ - int dead; - - float jumppower; - bool onground; - - int wentforweapon; - - bool calcrot; - - XYZ facing; - - float bleeding; - float bleedx, bleedy; - int direction; - float texupdatedelay; - - float headyaw, headpitch; - float targetheadyaw, targetheadpitch; - - bool onterrain; - bool pause; - - float grabdelay; - - std::shared_ptr victim; - bool hasvictim; - - float updatedelay; - float normalsupdatedelay; - - bool jumpstart; - - bool forwardkeydown; - bool forwardstogglekeydown; - bool rightkeydown; - bool leftkeydown; - bool backkeydown; - bool jumpkeydown; - bool jumptogglekeydown; - bool crouchkeydown; - bool crouchtogglekeydown; - bool drawkeydown; - bool drawtogglekeydown; - bool throwkeydown; - bool throwtogglekeydown; - bool attackkeydown; - bool feint; - bool lastfeint; - bool headless; - - float crouchkeydowntime; - float jumpkeydowntime; - bool freefall; - - - float turnspeed; - - int aitype; - float aiupdatedelay; - float losupdatedelay; - int ally; - float collide; - float collided; - float avoidcollided; - bool loaded; - bool whichdirection; - float whichdirectiondelay; - bool avoidsomething; - XYZ avoidwhere; - float blooddimamount; - - float staggerdelay; - float blinkdelay; - float twitchdelay; - float twitchdelay2; - float twitchdelay3; - float lefthandmorphness; - float righthandmorphness; - float headmorphness; - float chestmorphness; - float tailmorphness; - float targetlefthandmorphness; - float targetrighthandmorphness; - float targetheadmorphness; - float targetchestmorphness; - float targettailmorphness; - int lefthandmorphstart, lefthandmorphend; - int righthandmorphstart, righthandmorphend; - int headmorphstart, headmorphend; - int chestmorphstart, chestmorphend; - int tailmorphstart, tailmorphend; - - float weaponmissdelay; - float highreversaldelay; - float lowreversaldelay; - - int creature; - - unsigned id; - - Skeleton skeleton; - - float speed; - float scale; - float power; - float speedmult; - - float protectionhead; - float protectionhigh; - float protectionlow; - float armorhead; - float armorhigh; - float armorlow; - bool metalhead; - bool metalhigh; - bool metallow; - - int numclothes; - char clothes[10][256]; - float clothestintr[10]; - float clothestintg[10]; - float clothestintb[10]; - - bool landhard; - bool bled; - bool spurt; - bool onfire; - float onfiredelay; - float burnt; - - float flamedelay; - - int playerdetail; - - int num_weapons; - int weaponids[4]; - /* Key of weaponids which is the weapon in hand, if any. -1 otherwise. - * Always 0 or -1 as activeweapon is moved to position 0 when taken */ - int weaponactive; - int weaponstuck; - /* 0 or 1 to say if weapon is stuck in the front or the back */ - int weaponstuckwhere; - - int numwaypoints; - XYZ waypoints[90]; - int waypointtype[90]; - float pausetime; - - XYZ headtarget; - float interestdelay; - - XYZ finalfinaltarget; - XYZ finaltarget; - int finalpathfindpoint; - int targetpathfindpoint; - int lastpathfindpoint; - int lastpathfindpoint2; - int lastpathfindpoint3; - int lastpathfindpoint4; - - int waypoint; - - XYZ lastseen; - float lastseentime; - float lastchecktime; - float stunned; - float surprised; - float runninghowlong; - int occluded; - int lastoccluded; - int laststanding; - int escapednum; - - float speechdelay; - float neckspurtdelay; - float neckspurtparticledelay; - float neckspurtamount; - - int whichskin; - bool rabbitkickragdoll; - - Animation tempanimation; - - bool jumpclimb; - - Person(); - Person(FILE*, int, unsigned); - - void skeletonLoad(bool clothes = false); - - // convenience functions - inline Joint& joint(int bodypart) { return skeleton.joints[skeleton.jointlabels[bodypart]]; } - inline XYZ& jointPos(int bodypart) { return joint(bodypart).position; } - inline XYZ& jointVel(int bodypart) { return joint(bodypart).velocity; } - inline AnimationFrame& currentFrame() { return Animation::animations.at(animCurrent).frames.at(frameCurrent); } - inline AnimationFrame& targetFrame() { return Animation::animations.at(animTarget).frames.at(frameTarget); } - - - void CheckKick(); - void CatchFire(); - void DoBlood(float howmuch, int which); - void DoBloodBig(float howmuch, int which); - bool DoBloodBigWhere(float howmuch, int which, XYZ where); - - bool wasIdle() { return animation_bits[animCurrent] & ab_idle; } - bool isIdle() { return animation_bits[animTarget] & ab_idle; } - int getIdle(); - - bool isSitting() { return animation_bits[animTarget] & ab_sit; } - - bool isSleeping() { return animation_bits[animTarget] & ab_sleep; } - - bool wasCrouch() { return animation_bits[animCurrent] & ab_crouch; } - bool isCrouch() { return animation_bits[animTarget] & ab_crouch; } - int getCrouch(); - - bool wasStop() { return animation_bits[animCurrent] & ab_stop; } - bool isStop() { return animation_bits[animTarget] & ab_stop; } - int getStop(); - - bool wasSneak(); - bool isSneak(); - int getSneak(); - - bool wasRun() { return animation_bits[animCurrent] & ab_run; } - bool isRun() { return animation_bits[animTarget] & ab_run; } - int getRun(); - - bool wasLanding() { return animation_bits[animCurrent] & ab_land; } - bool isLanding() { return animation_bits[animTarget] & ab_land; } - int getLanding(); - - bool wasLandhard() { return animation_bits[animCurrent] & ab_landhard; } - bool isLandhard() { return animation_bits[animTarget] & ab_landhard; } - int getLandhard(); - - bool wasFlip() { return animation_bits[animCurrent] & ab_flip; } - bool isFlip() { return animation_bits[animTarget] & ab_flip; } - - bool isWallJump() { return animation_bits[animTarget] & ab_walljump; } - void Reverse(); - void DoDamage(float howmuch); - void DoHead(); - void DoMipmaps() { - skeleton.drawmodel.textureptr.bind(); - glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE); - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, skeleton.skinsize, skeleton.skinsize, 0, GL_RGB, GL_UNSIGNED_BYTE, &skeleton.skinText[0]); - } - - int SphereCheck(XYZ *p1, float radius, XYZ *p, XYZ *move, float *rotate, Model *model); - int DrawSkeleton(); - void Puff(int whichlabel); - void FootLand(bodypart whichfoot, float opacity); - void DoStuff(); - void setAnimation(int); - void DoAnimations(); - void RagDoll(bool checkcollision); - - void takeWeapon (int weaponId); - - bool addClothes(const int& clothesId); - void addClothes(); -}; - -const int maxplayers = 10; - -#endif diff --git a/Source/Objects/Person.hpp b/Source/Objects/Person.hpp new file mode 100644 index 0000000..62af3a6 --- /dev/null +++ b/Source/Objects/Person.hpp @@ -0,0 +1,402 @@ +/* +Copyright (C) 2003, 2010 - Wolfire Games +Copyright (C) 2010-2016 - Lugaru contributors (see AUTHORS file) + +This file is part of Lugaru. + +Lugaru is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +Lugaru is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with Lugaru. If not, see . +*/ + +#ifndef _PERSON_HPP_ +#define _PERSON_HPP_ + +#include "Animation/Animation.hpp" +#include "Animation/Skeleton.hpp" +#include "Environment/Terrain.hpp" +#include "Graphic/gamegl.hpp" +#include "Graphic/Models.hpp" +#include "Graphic/Sprite.hpp" +#include "Math/Quaternions.hpp" +#include "Objects/Weapons.hpp" + +#include +#include + +#define passivetype 0 +#define guardtype 1 +#define searchtype 2 +#define attacktype 3 +#define attacktypecutoff 4 +#define playercontrolled 5 +#define gethelptype 6 +#define getweapontype 7 +#define pathfindtype 8 + +#define rabbittype 0 +#define wolftype 1 + +struct InvalidPersonException : public exception { + const char * what () const throw () { + return "Invalid weapon number"; + } +}; + +class Person : public enable_shared_from_this +{ +public: + static std::vector> players; + + int whichpatchx; + int whichpatchz; + + // animCurrent and animTarget are used to interpolate between different animations + // (and for a bunch of other things). + // animations interpolate with one another at various speeds. + // animTarget seems to determine the combat state? + int animCurrent; + int animTarget; + + // frameCurrent and frameTarget are used to interpolate between the frames of an animation + // (e.g. the crouched animation has only two frames, lerped back and forth slowly). + // animations advance at various speeds. + int frameCurrent; + int frameTarget; + + int oldanimCurrent; + int oldanimTarget; + int oldframeCurrent; + int oldframeTarget; + + int howactive; + + float parriedrecently; + + bool superruntoggle; + + int lastattack, lastattack2, lastattack3; + + XYZ currentoffset, targetoffset, offset; + float target; + float transspeed; + + XYZ realoldcoords; + XYZ oldcoords; + XYZ coords; + XYZ velocity; + + XYZ proportionhead; + XYZ proportionlegs; + XYZ proportionarms; + XYZ proportionbody; + + float unconscioustime; + + bool immobile; + + float velspeed; + float targetyaw; + float targetrot; + float rot; + float oldrot; + float lookyaw; + float lookpitch; + float yaw; + float pitch; + float lowyaw; + float tilt; + float targettilt; + float tilt2; + float targettilt2; + bool rabbitkickenabled; + + float bloodloss; + float bleeddelay; + float skiddelay; + float skiddingdelay; + float deathbleeding; + float tempdeltav; + + float damagetolerance; + float damage; + float permanentdamage; + float superpermanentdamage; + float lastcollide; + /* Seems to be 0 = alive, 1 = unconscious, 2 = dead */ + int dead; + + float jumppower; + bool onground; + + int wentforweapon; + + bool calcrot; + + XYZ facing; + + float bleeding; + float bleedx, bleedy; + int direction; + float texupdatedelay; + + float headyaw, headpitch; + float targetheadyaw, targetheadpitch; + + bool onterrain; + bool pause; + + float grabdelay; + + std::shared_ptr victim; + bool hasvictim; + + float updatedelay; + float normalsupdatedelay; + + bool jumpstart; + + bool forwardkeydown; + bool forwardstogglekeydown; + bool rightkeydown; + bool leftkeydown; + bool backkeydown; + bool jumpkeydown; + bool jumptogglekeydown; + bool crouchkeydown; + bool crouchtogglekeydown; + bool drawkeydown; + bool drawtogglekeydown; + bool throwkeydown; + bool throwtogglekeydown; + bool attackkeydown; + bool feint; + bool lastfeint; + bool headless; + + float crouchkeydowntime; + float jumpkeydowntime; + bool freefall; + + + float turnspeed; + + int aitype; + float aiupdatedelay; + float losupdatedelay; + int ally; + float collide; + float collided; + float avoidcollided; + bool loaded; + bool whichdirection; + float whichdirectiondelay; + bool avoidsomething; + XYZ avoidwhere; + float blooddimamount; + + float staggerdelay; + float blinkdelay; + float twitchdelay; + float twitchdelay2; + float twitchdelay3; + float lefthandmorphness; + float righthandmorphness; + float headmorphness; + float chestmorphness; + float tailmorphness; + float targetlefthandmorphness; + float targetrighthandmorphness; + float targetheadmorphness; + float targetchestmorphness; + float targettailmorphness; + int lefthandmorphstart, lefthandmorphend; + int righthandmorphstart, righthandmorphend; + int headmorphstart, headmorphend; + int chestmorphstart, chestmorphend; + int tailmorphstart, tailmorphend; + + float weaponmissdelay; + float highreversaldelay; + float lowreversaldelay; + + int creature; + + unsigned id; + + Skeleton skeleton; + + float speed; + float scale; + float power; + float speedmult; + + float protectionhead; + float protectionhigh; + float protectionlow; + float armorhead; + float armorhigh; + float armorlow; + bool metalhead; + bool metalhigh; + bool metallow; + + int numclothes; + char clothes[10][256]; + float clothestintr[10]; + float clothestintg[10]; + float clothestintb[10]; + + bool landhard; + bool bled; + bool spurt; + bool onfire; + float onfiredelay; + float burnt; + + float flamedelay; + + int playerdetail; + + int num_weapons; + int weaponids[4]; + /* Key of weaponids which is the weapon in hand, if any. -1 otherwise. + * Always 0 or -1 as activeweapon is moved to position 0 when taken */ + int weaponactive; + int weaponstuck; + /* 0 or 1 to say if weapon is stuck in the front or the back */ + int weaponstuckwhere; + + int numwaypoints; + XYZ waypoints[90]; + int waypointtype[90]; + float pausetime; + + XYZ headtarget; + float interestdelay; + + XYZ finalfinaltarget; + XYZ finaltarget; + int finalpathfindpoint; + int targetpathfindpoint; + int lastpathfindpoint; + int lastpathfindpoint2; + int lastpathfindpoint3; + int lastpathfindpoint4; + + int waypoint; + + XYZ lastseen; + float lastseentime; + float lastchecktime; + float stunned; + float surprised; + float runninghowlong; + int occluded; + int lastoccluded; + int laststanding; + int escapednum; + + float speechdelay; + float neckspurtdelay; + float neckspurtparticledelay; + float neckspurtamount; + + int whichskin; + bool rabbitkickragdoll; + + Animation tempanimation; + + bool jumpclimb; + + Person(); + Person(FILE*, int, unsigned); + + void skeletonLoad(bool clothes = false); + + // convenience functions + inline Joint& joint(int bodypart) { return skeleton.joints[skeleton.jointlabels[bodypart]]; } + inline XYZ& jointPos(int bodypart) { return joint(bodypart).position; } + inline XYZ& jointVel(int bodypart) { return joint(bodypart).velocity; } + inline AnimationFrame& currentFrame() { return Animation::animations.at(animCurrent).frames.at(frameCurrent); } + inline AnimationFrame& targetFrame() { return Animation::animations.at(animTarget).frames.at(frameTarget); } + + + void CheckKick(); + void CatchFire(); + void DoBlood(float howmuch, int which); + void DoBloodBig(float howmuch, int which); + bool DoBloodBigWhere(float howmuch, int which, XYZ where); + + bool wasIdle() { return animation_bits[animCurrent] & ab_idle; } + bool isIdle() { return animation_bits[animTarget] & ab_idle; } + int getIdle(); + + bool isSitting() { return animation_bits[animTarget] & ab_sit; } + + bool isSleeping() { return animation_bits[animTarget] & ab_sleep; } + + bool wasCrouch() { return animation_bits[animCurrent] & ab_crouch; } + bool isCrouch() { return animation_bits[animTarget] & ab_crouch; } + int getCrouch(); + + bool wasStop() { return animation_bits[animCurrent] & ab_stop; } + bool isStop() { return animation_bits[animTarget] & ab_stop; } + int getStop(); + + bool wasSneak(); + bool isSneak(); + int getSneak(); + + bool wasRun() { return animation_bits[animCurrent] & ab_run; } + bool isRun() { return animation_bits[animTarget] & ab_run; } + int getRun(); + + bool wasLanding() { return animation_bits[animCurrent] & ab_land; } + bool isLanding() { return animation_bits[animTarget] & ab_land; } + int getLanding(); + + bool wasLandhard() { return animation_bits[animCurrent] & ab_landhard; } + bool isLandhard() { return animation_bits[animTarget] & ab_landhard; } + int getLandhard(); + + bool wasFlip() { return animation_bits[animCurrent] & ab_flip; } + bool isFlip() { return animation_bits[animTarget] & ab_flip; } + + bool isWallJump() { return animation_bits[animTarget] & ab_walljump; } + void Reverse(); + void DoDamage(float howmuch); + void DoHead(); + void DoMipmaps() { + skeleton.drawmodel.textureptr.bind(); + glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, skeleton.skinsize, skeleton.skinsize, 0, GL_RGB, GL_UNSIGNED_BYTE, &skeleton.skinText[0]); + } + + int SphereCheck(XYZ *p1, float radius, XYZ *p, XYZ *move, float *rotate, Model *model); + int DrawSkeleton(); + void Puff(int whichlabel); + void FootLand(bodypart whichfoot, float opacity); + void DoStuff(); + void setAnimation(int); + void DoAnimations(); + void RagDoll(bool checkcollision); + + void takeWeapon (int weaponId); + + bool addClothes(const int& clothesId); + void addClothes(); +}; + +const int maxplayers = 10; + +#endif diff --git a/Source/Objects/Weapons.cpp b/Source/Objects/Weapons.cpp index c56779d..0126c2e 100644 --- a/Source/Objects/Weapons.cpp +++ b/Source/Objects/Weapons.cpp @@ -20,14 +20,13 @@ You should have received a copy of the GNU General Public License along with Lugaru. If not, see . */ -/**> HEADER FILES <**/ -#include "Animation/Animation.h" -#include "Audio/openal_wrapper.h" -#include "Audio/Sounds.h" -#include "Level/Awards.h" -#include "Objects/Weapons.h" - -#include "Game.h" +#include "Objects/Weapons.hpp" + +#include "Animation/Animation.hpp" +#include "Audio/openal_wrapper.hpp" +#include "Audio/Sounds.hpp" +#include "Game.hpp" +#include "Level/Awards.hpp" extern float multiplier; extern Terrain terrain; diff --git a/Source/Objects/Weapons.h b/Source/Objects/Weapons.h deleted file mode 100644 index 51ab000..0000000 --- a/Source/Objects/Weapons.h +++ /dev/null @@ -1,133 +0,0 @@ -/* -Copyright (C) 2003, 2010 - Wolfire Games -Copyright (C) 2010-2016 - Lugaru contributors (see AUTHORS file) - -This file is part of Lugaru. - -Lugaru is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2 of the License, or -(at your option) any later version. - -Lugaru is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with Lugaru. If not, see . -*/ - -#ifndef _WEAPONS_H_ -#define _WEAPONS_H_ - -/**> HEADER FILES <**/ -#include "Animation/Skeleton.h" -#include "Environment/Terrain.h" -#include "Graphic/gamegl.h" -#include "Graphic/Models.h" -#include "Graphic/Sprite.h" -#include "Graphic/Texture.h" -#include "Math/Quaternions.h" -#include "Objects/Person.h" - -#include - -#define max_weapons 30 -#define max_weaponinstances 20 - -#define knife 1 -#define sword 2 -#define staff 3 - -class Weapon -{ -public: - Weapon(int type, int owner); - - static Model throwingknifemodel; - static Texture knifetextureptr; - static Texture lightbloodknifetextureptr; - static Texture bloodknifetextureptr; - - static Model swordmodel; - static Texture swordtextureptr; - static Texture lightbloodswordtextureptr; - static Texture bloodswordtextureptr; - - static Model staffmodel; - static Texture stafftextureptr; - - void Draw(); - void DoStuff(int); - - int getType() { - return type; - } - void setType(int); - - void drop(XYZ velocity, XYZ tipvelocity, bool sethitsomething = true); - void thrown(XYZ velocity, bool sethitsomething = true); - - int owner; - XYZ position; - XYZ tippoint; - XYZ velocity; - XYZ tipvelocity; - bool missed; - bool hitsomething; - float freetime; - bool firstfree; - bool physics; - - float damage; - int bloody; - float blooddrip; - float blooddripdelay; - - float rotation1; - float rotation2; - float rotation3; - float bigrotation; - float bigtilt; - float bigtilt2; - float smallrotation; - float smallrotation2; -private: - int type; - - XYZ oldtippoint; - XYZ oldposition; - int oldowner; - bool onfire; - float flamedelay; - float mass; - float tipmass; - float length; - float drawhowmany; - - XYZ lastdrawnposition; - XYZ lastdrawntippoint; - float lastdrawnrotation1; - float lastdrawnrotation2; - float lastdrawnrotation3; - float lastdrawnbigrotation; - float lastdrawnbigtilt; - float lastdrawnbigtilt2; - float lastdrawnsmallrotation; - float lastdrawnsmallrotation2; - int lastdrawnanim; -}; - -class Weapons : public std::vector -{ -public: - Weapons(); - ~Weapons(); - - int Draw(); - void DoStuff(); -}; - -extern Weapons weapons; -#endif diff --git a/Source/Objects/Weapons.hpp b/Source/Objects/Weapons.hpp new file mode 100644 index 0000000..9258e9e --- /dev/null +++ b/Source/Objects/Weapons.hpp @@ -0,0 +1,132 @@ +/* +Copyright (C) 2003, 2010 - Wolfire Games +Copyright (C) 2010-2016 - Lugaru contributors (see AUTHORS file) + +This file is part of Lugaru. + +Lugaru is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +Lugaru is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with Lugaru. If not, see . +*/ + +#ifndef _WEAPONS_HPP_ +#define _WEAPONS_HPP_ + +#include "Animation/Skeleton.hpp" +#include "Environment/Terrain.hpp" +#include "Graphic/gamegl.hpp" +#include "Graphic/Models.hpp" +#include "Graphic/Sprite.hpp" +#include "Graphic/Texture.hpp" +#include "Math/Quaternions.hpp" +#include "Objects/Person.hpp" + +#include + +#define max_weapons 30 +#define max_weaponinstances 20 + +#define knife 1 +#define sword 2 +#define staff 3 + +class Weapon +{ +public: + Weapon(int type, int owner); + + static Model throwingknifemodel; + static Texture knifetextureptr; + static Texture lightbloodknifetextureptr; + static Texture bloodknifetextureptr; + + static Model swordmodel; + static Texture swordtextureptr; + static Texture lightbloodswordtextureptr; + static Texture bloodswordtextureptr; + + static Model staffmodel; + static Texture stafftextureptr; + + void Draw(); + void DoStuff(int); + + int getType() { + return type; + } + void setType(int); + + void drop(XYZ velocity, XYZ tipvelocity, bool sethitsomething = true); + void thrown(XYZ velocity, bool sethitsomething = true); + + int owner; + XYZ position; + XYZ tippoint; + XYZ velocity; + XYZ tipvelocity; + bool missed; + bool hitsomething; + float freetime; + bool firstfree; + bool physics; + + float damage; + int bloody; + float blooddrip; + float blooddripdelay; + + float rotation1; + float rotation2; + float rotation3; + float bigrotation; + float bigtilt; + float bigtilt2; + float smallrotation; + float smallrotation2; +private: + int type; + + XYZ oldtippoint; + XYZ oldposition; + int oldowner; + bool onfire; + float flamedelay; + float mass; + float tipmass; + float length; + float drawhowmany; + + XYZ lastdrawnposition; + XYZ lastdrawntippoint; + float lastdrawnrotation1; + float lastdrawnrotation2; + float lastdrawnrotation3; + float lastdrawnbigrotation; + float lastdrawnbigtilt; + float lastdrawnbigtilt2; + float lastdrawnsmallrotation; + float lastdrawnsmallrotation2; + int lastdrawnanim; +}; + +class Weapons : public std::vector +{ +public: + Weapons(); + ~Weapons(); + + int Draw(); + void DoStuff(); +}; + +extern Weapons weapons; +#endif diff --git a/Source/User/Account.cpp b/Source/User/Account.cpp index ff4b04f..ed0a654 100644 --- a/Source/User/Account.cpp +++ b/Source/User/Account.cpp @@ -18,12 +18,14 @@ You should have received a copy of the GNU General Public License along with Lugaru. If not, see . */ -#include "User/Account.h" +#include "User/Account.hpp" + +#include "MacCompatibility.hpp" #include "Utils/binio.h" -#include "MacCompatibility.h" + #include -#include "string.h" #include +#include using namespace std; diff --git a/Source/User/Account.h b/Source/User/Account.h deleted file mode 100644 index 385c6fa..0000000 --- a/Source/User/Account.h +++ /dev/null @@ -1,133 +0,0 @@ -/* -Copyright (C) 2003, 2010 - Wolfire Games -Copyright (C) 2010-2016 - Lugaru contributors (see AUTHORS file) - -This file is part of Lugaru. - -Lugaru is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2 of the License, or -(at your option) any later version. - -Lugaru is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with Lugaru. If not, see . -*/ - -#ifndef _Account_H_ -#define _Account_H_ - -#include -#include -#include -#include - -struct CampaignProgress { - float highscore; - float fasttime; - float score; - float time; - std::vector choices; - CampaignProgress() { - highscore = 0; - fasttime = 0; - score = 0; - time = 0; - } -}; - -class Account -{ -public: - static void destroyActive(); - static void setActive(int i); - static void add(const std::string& name); - static Account& get(int i); - static void loadFile(std::string filename); - static void saveFile(std::string filename); - static int getNbAccounts(); - - static bool hasActive(); - static Account& active(); - - Account(const std::string& name = ""); - Account(FILE* tfile); - - void endGame(); - void winCampaignLevel(int choice, float score, float time); - void winLevel(int level, float score, float time); - - // getter and setters - int getDifficulty(); - void setDifficulty(int i) { - difficulty = i; - }; - const std::string& getName() { - return name; - }; - float getCampaignScore() { - return campaignProgress[currentCampaign].score; - }; - int getCampaignChoicesMade() { - return campaignProgress[currentCampaign].choices.size(); - }; - int getCampaignChoice(int i) { - return campaignProgress[currentCampaign].choices[i]; - }; - void setCampaignScore(int s) { - campaignProgress[currentCampaign].score = s; - if (s > campaignProgress[currentCampaign].highscore) - campaignProgress[currentCampaign].highscore = s; - }; - void setCampaignFinalTime(float t) { - campaignProgress[currentCampaign].time = t; - if ((t < campaignProgress[currentCampaign].fasttime) || ((campaignProgress[currentCampaign].fasttime == 0) && (t != 0))) - campaignProgress[currentCampaign].fasttime = t; - }; - float getCampaignFasttime() { - return campaignProgress[currentCampaign].fasttime; - }; - void resetFasttime() { - campaignProgress[currentCampaign].fasttime = 0; - }; - float getCampaignHighScore() { - return campaignProgress[currentCampaign].highscore; - }; - float getHighScore(int i) { - return highscore[i]; - }; - float getFastTime(int i) { - return fasttime[i]; - }; - int getProgress() { - return progress; - }; - std::string getCurrentCampaign() { - return currentCampaign; - }; - void setCurrentCampaign(const std::string& name); - -private: - //statics - static std::vector accounts; - static int i_active; - - void save(FILE* tfile); - - int difficulty; - int progress; // progress in challenge levels - float points; - float highscore[50]; - float fasttime[50]; - bool unlocked[60]; - std::string name; - - std::string currentCampaign; - std::map campaignProgress; -}; - -#endif diff --git a/Source/User/Account.hpp b/Source/User/Account.hpp new file mode 100644 index 0000000..3c9e2e2 --- /dev/null +++ b/Source/User/Account.hpp @@ -0,0 +1,133 @@ +/* +Copyright (C) 2003, 2010 - Wolfire Games +Copyright (C) 2010-2016 - Lugaru contributors (see AUTHORS file) + +This file is part of Lugaru. + +Lugaru is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +Lugaru is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with Lugaru. If not, see . +*/ + +#ifndef _ACCOUNT_HPP_ +#define _ACCOUNT_HPP_ + +#include +#include +#include +#include + +struct CampaignProgress { + float highscore; + float fasttime; + float score; + float time; + std::vector choices; + CampaignProgress() { + highscore = 0; + fasttime = 0; + score = 0; + time = 0; + } +}; + +class Account +{ +public: + static void destroyActive(); + static void setActive(int i); + static void add(const std::string& name); + static Account& get(int i); + static void loadFile(std::string filename); + static void saveFile(std::string filename); + static int getNbAccounts(); + + static bool hasActive(); + static Account& active(); + + Account(const std::string& name = ""); + Account(FILE* tfile); + + void endGame(); + void winCampaignLevel(int choice, float score, float time); + void winLevel(int level, float score, float time); + + // getter and setters + int getDifficulty(); + void setDifficulty(int i) { + difficulty = i; + }; + const std::string& getName() { + return name; + }; + float getCampaignScore() { + return campaignProgress[currentCampaign].score; + }; + int getCampaignChoicesMade() { + return campaignProgress[currentCampaign].choices.size(); + }; + int getCampaignChoice(int i) { + return campaignProgress[currentCampaign].choices[i]; + }; + void setCampaignScore(int s) { + campaignProgress[currentCampaign].score = s; + if (s > campaignProgress[currentCampaign].highscore) + campaignProgress[currentCampaign].highscore = s; + }; + void setCampaignFinalTime(float t) { + campaignProgress[currentCampaign].time = t; + if ((t < campaignProgress[currentCampaign].fasttime) || ((campaignProgress[currentCampaign].fasttime == 0) && (t != 0))) + campaignProgress[currentCampaign].fasttime = t; + }; + float getCampaignFasttime() { + return campaignProgress[currentCampaign].fasttime; + }; + void resetFasttime() { + campaignProgress[currentCampaign].fasttime = 0; + }; + float getCampaignHighScore() { + return campaignProgress[currentCampaign].highscore; + }; + float getHighScore(int i) { + return highscore[i]; + }; + float getFastTime(int i) { + return fasttime[i]; + }; + int getProgress() { + return progress; + }; + std::string getCurrentCampaign() { + return currentCampaign; + }; + void setCurrentCampaign(const std::string& name); + +private: + //statics + static std::vector accounts; + static int i_active; + + void save(FILE* tfile); + + int difficulty; + int progress; // progress in challenge levels + float points; + float highscore[50]; + float fasttime[50]; + bool unlocked[60]; + std::string name; + + std::string currentCampaign; + std::map campaignProgress; +}; + +#endif diff --git a/Source/User/Settings.cpp b/Source/User/Settings.cpp index 9948e63..5f7909e 100644 --- a/Source/User/Settings.cpp +++ b/Source/User/Settings.cpp @@ -18,10 +18,11 @@ You should have received a copy of the GNU General Public License along with Lugaru. If not, see . */ -#include "Game.h" -#include "User/Settings.h" -#include "Utils/Folders.h" -#include "Utils/Input.h" +#include "User/Settings.hpp" + +#include "Game.hpp" +#include "Utils/Folders.hpp" +#include "Utils/Input.hpp" using namespace Game; diff --git a/Source/User/Settings.h b/Source/User/Settings.h deleted file mode 100644 index e5f983a..0000000 --- a/Source/User/Settings.h +++ /dev/null @@ -1,60 +0,0 @@ -/* -Copyright (C) 2003, 2010 - Wolfire Games -Copyright (C) 2010-2016 - Lugaru contributors (see AUTHORS file) - -This file is part of Lugaru. - -Lugaru is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2 of the License, or -(at your option) any later version. - -Lugaru is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with Lugaru. If not, see . -*/ - -#ifndef SETTINGS_H_ -#define SETTINGS_H_ - -#include "Game.h" - -extern float usermousesensitivity; -extern bool ismotionblur; -extern bool floatjump; -extern bool mousejump; -extern bool ambientsound; -extern int bloodtoggle; -extern bool autoslomo; -extern bool foliage; -extern bool musictoggle; -extern bool trilinear; -extern bool decals; -extern bool invertmouse; -extern float gamespeed; -extern float oldgamespeed; -extern bool damageeffects; -extern bool texttoggle; -extern bool devtools; -extern bool showpoints; -extern bool showdamagebar; -extern bool alwaysblur; -extern bool immediate; -extern bool velocityblur; -extern float volume; -extern int detail; -extern int kContextWidth; -extern int kContextHeight; -extern float screenwidth, screenheight; -extern bool fullscreen; - -void DefaultSettings(); -void SaveSettings(); -bool LoadSettings(); - - -#endif diff --git a/Source/User/Settings.hpp b/Source/User/Settings.hpp new file mode 100644 index 0000000..ca5327c --- /dev/null +++ b/Source/User/Settings.hpp @@ -0,0 +1,60 @@ +/* +Copyright (C) 2003, 2010 - Wolfire Games +Copyright (C) 2010-2016 - Lugaru contributors (see AUTHORS file) + +This file is part of Lugaru. + +Lugaru is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +Lugaru is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with Lugaru. If not, see . +*/ + +#ifndef _SETTINGS_HPP_ +#define _SETTINGS_HPP_ + +#include "Game.hpp" + +extern float usermousesensitivity; +extern bool ismotionblur; +extern bool floatjump; +extern bool mousejump; +extern bool ambientsound; +extern int bloodtoggle; +extern bool autoslomo; +extern bool foliage; +extern bool musictoggle; +extern bool trilinear; +extern bool decals; +extern bool invertmouse; +extern float gamespeed; +extern float oldgamespeed; +extern bool damageeffects; +extern bool texttoggle; +extern bool devtools; +extern bool showpoints; +extern bool showdamagebar; +extern bool alwaysblur; +extern bool immediate; +extern bool velocityblur; +extern float volume; +extern int detail; +extern int kContextWidth; +extern int kContextHeight; +extern float screenwidth, screenheight; +extern bool fullscreen; + +void DefaultSettings(); +void SaveSettings(); +bool LoadSettings(); + + +#endif diff --git a/Source/Utils/Folders.cpp b/Source/Utils/Folders.cpp index b667daa..e2956e5 100644 --- a/Source/Utils/Folders.cpp +++ b/Source/Utils/Folders.cpp @@ -18,17 +18,20 @@ You should have received a copy of the GNU General Public License along with Lugaru. If not, see . */ -#include "Folders.h" +#include "Folders.hpp" + #include #include + #if PLATFORM_UNIX +#include #include #include -#include #endif + #if _WIN32 -#include #include // to get paths related functions +#include #endif const std::string Folders::dataDir = DATA_DIR; diff --git a/Source/Utils/Folders.h b/Source/Utils/Folders.h deleted file mode 100644 index 495f149..0000000 --- a/Source/Utils/Folders.h +++ /dev/null @@ -1,67 +0,0 @@ -/* -Copyright (C) 2003, 2010 - Wolfire Games -Copyright (C) 2010-2016 - Lugaru contributors (see AUTHORS file) - -This file is part of Lugaru. - -Lugaru is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2 of the License, or -(at your option) any later version. - -Lugaru is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with Lugaru. If not, see . -*/ - -#ifndef _FOLDERS_H_ -#define _FOLDERS_H_ - -#include - -#ifndef DATA_DIR -#define DATA_DIR "Data" -#endif - -struct FileNotFoundException: public std::exception -{ - std::string errorText; - FileNotFoundException (const std::string& filename) { - errorText = filename + " could not be found"; - } - - const char * what () const throw () { - return errorText.c_str(); - } -}; - -class Folders -{ - static const std::string dataDir; - -public: - /* Returns path to the screenshot directory. Creates it if needed. */ - static std::string getScreenshotDir(); - - /* Returns full path for a game resource */ - static std::string getResourcePath(std::string filepath); - - /* Returns full path for user data */ - static std::string getUserDataPath(); - - /* Returns full path for config file */ - static std::string getConfigFilePath(); - - static FILE* openMandatoryFile(std::string filename, const char* mode); - -private: - static const char* getHomeDirectory(); - static std::string getGenericDirectory(const char* ENVVAR, const std::string fallback); - static bool makeDirectory(std::string path); -}; - -#endif /* _FOLDERS_H_ */ diff --git a/Source/Utils/Folders.hpp b/Source/Utils/Folders.hpp new file mode 100644 index 0000000..52be0f0 --- /dev/null +++ b/Source/Utils/Folders.hpp @@ -0,0 +1,67 @@ +/* +Copyright (C) 2003, 2010 - Wolfire Games +Copyright (C) 2010-2016 - Lugaru contributors (see AUTHORS file) + +This file is part of Lugaru. + +Lugaru is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +Lugaru is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with Lugaru. If not, see . +*/ + +#ifndef _FOLDERS_HPP_ +#define _FOLDERS_HPP_ + +#include + +#ifndef DATA_DIR +#define DATA_DIR "Data" +#endif + +struct FileNotFoundException: public std::exception +{ + std::string errorText; + FileNotFoundException (const std::string& filename) { + errorText = filename + " could not be found"; + } + + const char * what () const throw () { + return errorText.c_str(); + } +}; + +class Folders +{ + static const std::string dataDir; + +public: + /* Returns path to the screenshot directory. Creates it if needed. */ + static std::string getScreenshotDir(); + + /* Returns full path for a game resource */ + static std::string getResourcePath(std::string filepath); + + /* Returns full path for user data */ + static std::string getUserDataPath(); + + /* Returns full path for config file */ + static std::string getConfigFilePath(); + + static FILE* openMandatoryFile(std::string filename, const char* mode); + +private: + static const char* getHomeDirectory(); + static std::string getGenericDirectory(const char* ENVVAR, const std::string fallback); + static bool makeDirectory(std::string path); +}; + +#endif /* _FOLDERS_H_ */ diff --git a/Source/Utils/ImageIO.cpp b/Source/Utils/ImageIO.cpp index 7a405fc..778492c 100644 --- a/Source/Utils/ImageIO.cpp +++ b/Source/Utils/ImageIO.cpp @@ -18,17 +18,16 @@ You should have received a copy of the GNU General Public License along with Lugaru. If not, see . */ -/**> HEADER FILES <**/ +#include "Utils/ImageIO.hpp" + +#include "Game.hpp" +#include "Utils/Folders.hpp" -#include #include #include +#include #include -#include "Game.h" -#include "Utils/ImageIO.h" -#include "Utils/Folders.h" - extern bool visibleloading; /* These two are needed for screenshot */ diff --git a/Source/Utils/ImageIO.h b/Source/Utils/ImageIO.h deleted file mode 100644 index 0c587bf..0000000 --- a/Source/Utils/ImageIO.h +++ /dev/null @@ -1,62 +0,0 @@ -/* -Copyright (C) 2003, 2010 - Wolfire Games -Copyright (C) 2010-2016 - Lugaru contributors (see AUTHORS file) - -This file is part of Lugaru. - -Lugaru is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2 of the License, or -(at your option) any later version. - -Lugaru is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with Lugaru. If not, see . -*/ - -#ifndef _IMAGE_IO_H_ -#define _IMAGE_IO_H_ - -#ifdef _MSC_VER -#pragma once -#endif - - -/**> HEADER FILES <**/ -#include -#include -#include -#ifdef WIN32 -#define WIN32_LEAN_AND_MEAN -#define Polygon WinPolygon -#include -#undef Polygon -#include "GL/gl.h" -#else -#include "Graphic/gamegl.h" -#endif - -/**> DATA STRUCTURES <**/ -class ImageRec { -public: - GLubyte *data; // Image Data (Up To 32 Bits) - GLuint bpp; // Image Color Depth In Bits Per Pixel. - GLuint sizeX; - GLuint sizeY; - ImageRec(); - ~ImageRec(); -private: - /* Make sure this class cannot be copied to avoid memory problems */ - ImageRec(ImageRec const &); - ImageRec& operator=(ImageRec const &); -}; - -bool load_image(const char * fname, ImageRec & tex); -bool save_screenshot(const char * fname); - -#endif - diff --git a/Source/Utils/ImageIO.hpp b/Source/Utils/ImageIO.hpp new file mode 100644 index 0000000..6b43bad --- /dev/null +++ b/Source/Utils/ImageIO.hpp @@ -0,0 +1,61 @@ +/* +Copyright (C) 2003, 2010 - Wolfire Games +Copyright (C) 2010-2016 - Lugaru contributors (see AUTHORS file) + +This file is part of Lugaru. + +Lugaru is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +Lugaru is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with Lugaru. If not, see . +*/ + +#ifndef _IMAGE_IO_HPP_ +#define _IMAGE_IO_HPP_ + +#ifdef _MSC_VER +#pragma once +#endif + +#include +#include +#include + +#ifdef WIN32 +#define WIN32_LEAN_AND_MEAN +#define Polygon WinPolygon +#include +#undef Polygon +#include +#else +#include "Graphic/gamegl.hpp" +#endif + +/**> DATA STRUCTURES <**/ +class ImageRec { +public: + GLubyte *data; // Image Data (Up To 32 Bits) + GLuint bpp; // Image Color Depth In Bits Per Pixel. + GLuint sizeX; + GLuint sizeY; + ImageRec(); + ~ImageRec(); +private: + /* Make sure this class cannot be copied to avoid memory problems */ + ImageRec(ImageRec const &); + ImageRec& operator=(ImageRec const &); +}; + +bool load_image(const char * fname, ImageRec & tex); +bool save_screenshot(const char * fname); + +#endif + diff --git a/Source/Utils/Input.cpp b/Source/Utils/Input.cpp index 9376522..30667c7 100644 --- a/Source/Utils/Input.cpp +++ b/Source/Utils/Input.cpp @@ -18,8 +18,7 @@ You should have received a copy of the GNU General Public License along with Lugaru. If not, see . */ -/**> HEADER FILES <**/ -#include "Utils/Input.h" +#include "Utils/Input.hpp" bool keyDown[SDL_NUM_SCANCODES + 6]; bool keyPressed[SDL_NUM_SCANCODES + 6]; diff --git a/Source/Utils/Input.h b/Source/Utils/Input.h deleted file mode 100644 index 3bf8d79..0000000 --- a/Source/Utils/Input.h +++ /dev/null @@ -1,45 +0,0 @@ -/* -Copyright (C) 2003, 2010 - Wolfire Games -Copyright (C) 2010-2016 - Lugaru contributors (see AUTHORS file) - -This file is part of Lugaru. - -Lugaru is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2 of the License, or -(at your option) any later version. - -Lugaru is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with Lugaru. If not, see . -*/ - -#ifndef _Input_H_ -#define _Input_H_ - -/**> HEADER FILES <**/ -#include "SDL.h" -#include "Game.h" - -/**> CONSTANT DECLARATIONS <**/ -#define MOUSEBUTTON1 (SDL_NUM_SCANCODES + SDL_BUTTON_LEFT) -#define MOUSEBUTTON2 (SDL_NUM_SCANCODES + SDL_BUTTON_RIGHT) -#define MOUSEBUTTON3 (SDL_NUM_SCANCODES + SDL_BUTTON_MIDDLE) - -/**> FUNCTION PROTOTYPES <**/ -class Input -{ -public: - static void Tick(); - static bool isKeyDown(int k); - static bool isKeyPressed(int k); - static const char* keyToChar(unsigned short which); - static unsigned short CharToKey(const char* which); - static bool MouseClicked(); -}; - -#endif diff --git a/Source/Utils/Input.hpp b/Source/Utils/Input.hpp new file mode 100644 index 0000000..af83cb1 --- /dev/null +++ b/Source/Utils/Input.hpp @@ -0,0 +1,45 @@ +/* +Copyright (C) 2003, 2010 - Wolfire Games +Copyright (C) 2010-2016 - Lugaru contributors (see AUTHORS file) + +This file is part of Lugaru. + +Lugaru is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +Lugaru is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with Lugaru. If not, see . +*/ + +#ifndef _INPUT_HPP_ +#define _INPUT_HPP_ + +#include "Game.hpp" + +#include + +/**> CONSTANT DECLARATIONS <**/ +#define MOUSEBUTTON1 (SDL_NUM_SCANCODES + SDL_BUTTON_LEFT) +#define MOUSEBUTTON2 (SDL_NUM_SCANCODES + SDL_BUTTON_RIGHT) +#define MOUSEBUTTON3 (SDL_NUM_SCANCODES + SDL_BUTTON_MIDDLE) + +/**> FUNCTION PROTOTYPES <**/ +class Input +{ +public: + static void Tick(); + static bool isKeyDown(int k); + static bool isKeyPressed(int k); + static const char* keyToChar(unsigned short which); + static unsigned short CharToKey(const char* which); + static bool MouseClicked(); +}; + +#endif diff --git a/Source/Utils/pack.c b/Source/Utils/pack.c index 736085d..da5c2ae 100644 --- a/Source/Utils/pack.c +++ b/Source/Utils/pack.c @@ -18,11 +18,11 @@ You should have received a copy of the GNU General Public License along with Lugaru. If not, see . */ -#include - #include "binio.h" #include "private.h" +#include + struct BinIOPackContext { uint8_t *buffer; va_list args; diff --git a/Source/Utils/private.c b/Source/Utils/private.c index 6ff2b59..3e37728 100644 --- a/Source/Utils/private.c +++ b/Source/Utils/private.c @@ -18,10 +18,10 @@ You should have received a copy of the GNU General Public License along with Lugaru. If not, see . */ -#include - #include "private.h" +#include + void BinIOConvert1(int from_byte_order, int to_byte_order, const uint8_t *src, uint8_t *dst, unsigned int count) diff --git a/Source/Utils/unpack.c b/Source/Utils/unpack.c index fbcce38..5a31c91 100644 --- a/Source/Utils/unpack.c +++ b/Source/Utils/unpack.c @@ -18,11 +18,11 @@ You should have received a copy of the GNU General Public License along with Lugaru. If not, see . */ -#include - #include "binio.h" #include "private.h" +#include + struct BinIOUnpackContext { const uint8_t *data; va_list args; diff --git a/Source/WinDefs.cpp b/Source/WinDefs.cpp index b032f5e..4557d1e 100644 --- a/Source/WinDefs.cpp +++ b/Source/WinDefs.cpp @@ -18,12 +18,12 @@ You should have received a copy of the GNU General Public License along with Lugaru. If not, see . */ -/**> HEADER FILES <**/ -#include "WinDefs.h" -#include +#include "WinDefs.hpp" + #include -#include #include +#include +#include class AppTime diff --git a/Source/WinDefs.h b/Source/WinDefs.h deleted file mode 100644 index 3668453..0000000 --- a/Source/WinDefs.h +++ /dev/null @@ -1,94 +0,0 @@ -/* -Copyright (C) 2003, 2010 - Wolfire Games -Copyright (C) 2010-2016 - Lugaru contributors (see AUTHORS file) - -This file is part of Lugaru. - -Lugaru is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2 of the License, or -(at your option) any later version. - -Lugaru is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with Lugaru. If not, see . -*/ - -#ifndef _WINDEFS_H_ -#define _WINDEFS_H_ -#ifdef WIN32 - - -#include -#include - -// stuff to make Mac code compatable with Windows - - -// disable warnings about double to float conversions -#pragma warning(disable:4305) -#pragma warning(disable:4244) - -// disable warnings about boolean to int conversions -#pragma warning(disable:4800) - -// disable warning about unreferenced local variables -#pragma warning(disable:4101) - -struct Point { - short v; - short h; -}; - -typedef signed char SInt8; -typedef unsigned int UInt32; - - -#include "Math/Random.h" - - -typedef struct AbsoluteTime { - unsigned long hi; - unsigned long lo; -} AbsoluteTime; - -AbsoluteTime UpTime(); // NOTE: returns time since app started, not system start - -typedef long Duration; - -enum { - durationMicrosecond = -1, - durationMillisecond = 1, - durationSecond = 1000, - durationMinute = 1000 * 60, - durationHour = 1000 * 60 * 60, - durationDay = 1000 * 60 * 60 * 24, - durationForever = 0x7FFFFFFF, - durationImmediate = 0, -}; - -Duration AbsoluteDeltaToDuration( AbsoluteTime& a, AbsoluteTime& b); - -#ifndef __MINGW32__ -inline float abs(float f) -{ - if (f < 0) - return -f; - return f; -} - -inline double abs(double f) -{ - if (f < 0) - return -f; - return f; -} -#endif // __MINGW32__ - - -#endif -#endif diff --git a/Source/WinDefs.hpp b/Source/WinDefs.hpp new file mode 100644 index 0000000..ab4113b --- /dev/null +++ b/Source/WinDefs.hpp @@ -0,0 +1,91 @@ +/* +Copyright (C) 2003, 2010 - Wolfire Games +Copyright (C) 2010-2016 - Lugaru contributors (see AUTHORS file) + +This file is part of Lugaru. + +Lugaru is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +Lugaru is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with Lugaru. If not, see . +*/ + +#ifndef _WINDEFS_HPP_ +#define _WINDEFS_HPP_ +#ifdef WIN32 + +#include +#include + +#include "Math/Random.hpp" + +// stuff to make Mac code compatable with Windows + +// disable warnings about double to float conversions +#pragma warning(disable:4305) +#pragma warning(disable:4244) + +// disable warnings about boolean to int conversions +#pragma warning(disable:4800) + +// disable warning about unreferenced local variables +#pragma warning(disable:4101) + +struct Point { + short v; + short h; +}; + +typedef signed char SInt8; +typedef unsigned int UInt32; + + +typedef struct AbsoluteTime { + unsigned long hi; + unsigned long lo; +} AbsoluteTime; + +AbsoluteTime UpTime(); // NOTE: returns time since app started, not system start + +typedef long Duration; + +enum { + durationMicrosecond = -1, + durationMillisecond = 1, + durationSecond = 1000, + durationMinute = 1000 * 60, + durationHour = 1000 * 60 * 60, + durationDay = 1000 * 60 * 60 * 24, + durationForever = 0x7FFFFFFF, + durationImmediate = 0, +}; + +Duration AbsoluteDeltaToDuration( AbsoluteTime& a, AbsoluteTime& b); + +#ifndef __MINGW32__ +inline float abs(float f) +{ + if (f < 0) + return -f; + return f; +} + +inline double abs(double f) +{ + if (f < 0) + return -f; + return f; +} +#endif // __MINGW32__ + + +#endif +#endif diff --git a/Source/main.cpp b/Source/main.cpp index 2144a8c..8463907 100644 --- a/Source/main.cpp +++ b/Source/main.cpp @@ -18,27 +18,27 @@ You should have received a copy of the GNU General Public License along with Lugaru. If not, see . */ +#include "Game.hpp" + +#include "Audio/openal_wrapper.hpp" +#include "Graphic/gamegl.hpp" +#include "MacCompatibility.hpp" +#include "User/Settings.hpp" + +#include +#include #include +#include #include #include -#include -#include #include -#include -#include "MacCompatibility.h" -#include "Graphic/gamegl.h" -#include "User/Settings.h" - -#include "Game.h" using namespace Game; -#include "Audio/openal_wrapper.h" - #ifdef WIN32 -#include #include -#include "win-res/resource.h" +#include +#include "win-res/resource.hpp" #endif extern float multiplier; diff --git a/Source/win-res/resource.h b/Source/win-res/resource.h deleted file mode 100644 index 3583ba6..0000000 --- a/Source/win-res/resource.h +++ /dev/null @@ -1,36 +0,0 @@ -/* -Copyright (C) 2003, 2010 - Wolfire Games -Copyright (C) 2010-2016 - Lugaru contributors (see AUTHORS file) - -This file is part of Lugaru. - -Lugaru is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2 of the License, or -(at your option) any later version. - -Lugaru is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with Lugaru. If not, see . -*/ - -//{{NO_DEPENDENCIES}} -// Microsoft Visual C++ generated include file. -// Used by Lugaru.rc -// -#define IDI_LUGARU 104 - -// Next default values for new objects -// -#ifdef APSTUDIO_INVOKED -#ifndef APSTUDIO_READONLY_SYMBOLS -#define _APS_NEXT_RESOURCE_VALUE 105 -#define _APS_NEXT_COMMAND_VALUE 40001 -#define _APS_NEXT_CONTROL_VALUE 1001 -#define _APS_NEXT_SYMED_VALUE 101 -#endif -#endif diff --git a/Source/win-res/resource.hpp b/Source/win-res/resource.hpp new file mode 100644 index 0000000..3583ba6 --- /dev/null +++ b/Source/win-res/resource.hpp @@ -0,0 +1,36 @@ +/* +Copyright (C) 2003, 2010 - Wolfire Games +Copyright (C) 2010-2016 - Lugaru contributors (see AUTHORS file) + +This file is part of Lugaru. + +Lugaru is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +Lugaru is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with Lugaru. If not, see . +*/ + +//{{NO_DEPENDENCIES}} +// Microsoft Visual C++ generated include file. +// Used by Lugaru.rc +// +#define IDI_LUGARU 104 + +// Next default values for new objects +// +#ifdef APSTUDIO_INVOKED +#ifndef APSTUDIO_READONLY_SYMBOLS +#define _APS_NEXT_RESOURCE_VALUE 105 +#define _APS_NEXT_COMMAND_VALUE 40001 +#define _APS_NEXT_CONTROL_VALUE 1001 +#define _APS_NEXT_SYMED_VALUE 101 +#endif +#endif