HGamer3D-Enet-Binding 0.3.1 → 0.3.2
raw patch · 10 files changed
+366/−8 lines, 10 files
Files
- HGamer3D-Enet-Binding.cabal +4/−4
- include/ClassEnet.h +44/−0
- include/ClassEnetClient.h +49/−0
- include/ClassEnetPacket.h +42/−0
- include/ClassEnetServer.h +43/−0
- include/ClassPtr.h +50/−0
- include/EnetDllDefines.h +41/−0
- include/StructHG3DClass.h +29/−0
- include/hg3denet.hpp +64/−0
- include/hg3dstruct.h +0/−4
HGamer3D-Enet-Binding.cabal view
@@ -1,5 +1,5 @@ Name: HGamer3D-Enet-Binding -Version: 0.3.1 +Version: 0.3.2 Synopsis: Enet Binding for HGamer3D Description: HGamer3D is a game engine for developing 3D games in the programming @@ -19,7 +19,7 @@ Cabal-Version: >=1.4 Homepage: http://www.hgamer3d.org Category: Game Engine, Network -Extra-source-files: Setup.hs, include/hg3dstruct.h +Extra-source-files: Setup.hs, include/ClassEnetPacket.h, include/StructHG3DClass.h, include/ClassEnetClient.h, include/hg3denet.hpp, include/ClassEnetServer.h, include/ClassEnet.h, include/EnetDllDefines.h, include/ClassPtr.h Library Build-Depends: base >= 3 && < 5, HGamer3D-Data >= 0.3.0 @@ -34,6 +34,6 @@ Build-tools: build-depends: if os(windows) - extra-libraries: hg3denet031 + extra-libraries: hg3denet032 else - extra-libraries: hg3denet031,enet + extra-libraries: hg3denet032,enet
+ include/ClassEnet.h view
@@ -0,0 +1,44 @@+// This source file is part of HGamer3D, a project to enable 3D game development +// in Haskell. For the latest info, see http://www.hgamer3d.org . +// +// (c) 2011-2014 Peter Althainz +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +// ClassEnet.h + +// + +#include "wchar.h" +#ifndef _DEFINED_HG3D_ClassEnet+#define _DEFINED_HG3D_ClassEnet++#include "ClassPtr.h"+#include "ClassEnetServer.h"+#include "ClassEnetClient.h"+ + +// +void enet_enet_construct(struct hg3dclass_struct * result_c);++// +void enet_enet_destruct(struct hg3dclass_struct * thisclass_c);++// +void enet_enet_createServer(int port_c, struct hg3dclass_struct * result_c);++// +void enet_enet_createClient(struct hg3dclass_struct * result_c);++#endif
+ include/ClassEnetClient.h view
@@ -0,0 +1,49 @@+// This source file is part of HGamer3D, a project to enable 3D game development +// in Haskell. For the latest info, see http://www.hgamer3d.org . +// +// (c) 2011-2014 Peter Althainz +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +// ClassEnetClient.h + +// + +#include "wchar.h" +#ifndef _DEFINED_HG3D_ClassEnetClient+#define _DEFINED_HG3D_ClassEnetClient++#include "ClassPtr.h"+#include "ClassEnetPacket.h"+ + +// +void enet_clnt_destruct(struct hg3dclass_struct * thisclass_c);++// +void enet_clnt_connect(struct hg3dclass_struct * thisclass_c, char * server_c, int port_c, int * result_c);++// +void enet_clnt_disconnect(struct hg3dclass_struct * thisclass_c, int * result_c);++// +void enet_clnt_serve(struct hg3dclass_struct * thisclass_c, int msWait_c, int * result_c);++// +void enet_clnt_getPacket(struct hg3dclass_struct * thisclass_c, struct hg3dclass_struct * result_c);++// +void enet_clnt_send(struct hg3dclass_struct * thisclass_c, char * message_c, int channel_c);++#endif
+ include/ClassEnetPacket.h view
@@ -0,0 +1,42 @@+// This source file is part of HGamer3D, a project to enable 3D game development +// in Haskell. For the latest info, see http://www.hgamer3d.org . +// +// (c) 2011-2014 Peter Althainz +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +// ClassEnetPacket.h + +// + +#include "wchar.h" +#ifndef _DEFINED_HG3D_ClassEnetPacket+#define _DEFINED_HG3D_ClassEnetPacket++#include "ClassPtr.h"+ + +// +void enet_pck_getData(struct hg3dclass_struct * thisclass_c, char * result_c);++// +void enet_pck_getPeer(struct hg3dclass_struct * thisclass_c, char * result_c);++// +void enet_pck_getChannel(struct hg3dclass_struct * thisclass_c, int * result_c);++// +void enet_pck_destruct(struct hg3dclass_struct * thisclass_c);++#endif
+ include/ClassEnetServer.h view
@@ -0,0 +1,43 @@+// This source file is part of HGamer3D, a project to enable 3D game development +// in Haskell. For the latest info, see http://www.hgamer3d.org . +// +// (c) 2011-2014 Peter Althainz +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +// ClassEnetServer.h + +// + +#include "wchar.h" +#ifndef _DEFINED_HG3D_ClassEnetServer+#define _DEFINED_HG3D_ClassEnetServer++#include "ClassPtr.h"+#include "ClassEnetPacket.h"+ + +// +void enet_srv_destruct(struct hg3dclass_struct * thisclass_c);++// +void enet_srv_serve(struct hg3dclass_struct * thisclass_c, int msWait_c, int * result_c);++// +void enet_srv_getPacket(struct hg3dclass_struct * thisclass_c, struct hg3dclass_struct * result_c);++// +void enet_srv_send(struct hg3dclass_struct * thisclass_c, char * peer_c, char * message_c, int channel_c);++#endif
+ include/ClassPtr.h view
@@ -0,0 +1,50 @@+// This source file is part of HGamer3D, a project to enable 3D game development +// in Haskell. For the latest info, see http://www.hgamer3d.org . +// +// (c) 2011-2014 Peter Althainz +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +// ClassPtr.h + +// Here are the methods defined, which do the class pointer+// marshalling and the casting of subclasses to higher classes+ +#include "wchar.h" + + +#ifndef CLASSPTR_INCLUDE_H+#define CLASSPTR_INCLUDE_H++typedef struct hg3dclass_struct {+ void *ptr;+ void *fptr;+} hg3dclass_struct;++void *getHG3DClassPtr(hg3dclass_struct inSt, const char* className);+++typedef void ClassEnetClient; +hg3dclass_struct getHG3DClass_EnetClient(void *ptrIn);++typedef void ClassEnetPacket; +hg3dclass_struct getHG3DClass_EnetPacket(void *ptrIn);++typedef void ClassEnetServer; +hg3dclass_struct getHG3DClass_EnetServer(void *ptrIn);++typedef void ClassHG3DEnet; +hg3dclass_struct getHG3DClass_HG3DEnet(void *ptrIn);++#endif
+ include/EnetDllDefines.h view
@@ -0,0 +1,41 @@+// (c) 2011-2014 Peter Althainz +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + + +// EnetDllDefines.h + +#ifndef _HGamer3DEnet032_DLLDEFINES_H_ +#define _HGamer3DEnet032_DLLDEFINES_H_ + +/* Cmake will define HGamer3DEnet032_EXPORTS on Windows when it +configures to build a shared library. If you are going to use +another build system on windows or create the visual studio +projects by hand you need to define MyLibrary_EXPORTS when +building a DLL on windows. +*/ + +// We are using the Visual Studio Compiler and building Shared libraries + +#if (defined (_WIN32)) && !(defined (__GNUC__)) + #if defined(HGamer3DEnet032_EXPORTS) + #define Enet_LIB_EXPORT __declspec(dllexport) + #else + #define Enet_LIB_EXPORT __declspec(dllimport) + #endif /* HGamer3DEnet032_EXPORTS */ +#else /* defined (_WIN32) */ + #define Enet_LIB_EXPORT +#endif + +#endif /* _HGamer3DEnet032_DLLDEFINES_H_ */
+ include/StructHG3DClass.h view
@@ -0,0 +1,29 @@+// This source file is part of HGamer3D, a project to enable 3D game development +// in Haskell. For the latest info, see http://www.hgamer3d.org . +// +// (c) 2011-2014 Peter Althainz +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +// StructHG3DClass.h + +// + +#include "wchar.h" + + +typedef struct hg3dclass_struct {+ void *ptr;+ void *fptr;+} hg3dclass_struct;
+ include/hg3denet.hpp view
@@ -0,0 +1,64 @@+#include "enet/enet.h"+#include "deque"+#include "map"+#include "string"++using namespace std;++class EnetPacket+{+ ENetPacket* m_packet;+ char m_peer[128];+ int m_channel;+ EnetPacket(ENetPacket* packet, ENetPeer* peer, int channel);++public:+ char* getData();+ char* getPeer();+ int getChannel();+ ~EnetPacket();+ friend class EnetServer;+ friend class EnetClient;+};+++class EnetServer+{+ deque<EnetPacket*> m_packets;+ map<string,ENetPeer*> m_peers; + ENetHost *m_server;+ EnetServer(ENetHost* server);+public:+ ~EnetServer();+ bool serve(int msWait);+ EnetPacket* getPacket();+ void send(const char* peer, const char* message, int channel);+ friend class HG3DEnet;+};++class EnetClient+{+ ENetHost *m_client;+ ENetPeer *m_peer;+ EnetClient(ENetHost* client);+ deque<EnetPacket*> m_packets;+public:+ ~EnetClient();+ bool connect(const char* server, int port);+ bool disconnect();+ bool serve(int msWait);+ EnetPacket* getPacket();+ void send(const char* message, int channel);+ friend class HG3DEnet;+};++++class HG3DEnet+{+public:+ HG3DEnet();+ ~HG3DEnet();+ static EnetServer* createServer(int port); + static EnetClient* createClient();+};
− include/hg3dstruct.h
@@ -1,4 +0,0 @@-typedef struct hg3dclass_struct {- void *ptr;- void *fptr;-} hg3dclass_struct;