From b95d0476ce6535c733cb39b784625d67cb25a150 Mon Sep 17 00:00:00 2001
From: chai <chaifix@163.com>
Date: Sat, 28 Jul 2018 23:33:38 +0800
Subject: *update

---
 build/libjin/libjin.vcxproj                  |  2 +
 build/libjin/libjin.vcxproj.filters          |  9 ++++
 libjin/Core/Game.cpp                         |  7 ++-
 libjin/Core/Game.h                           |  2 +-
 libjin/Graphics/Drawable.h                   |  2 +
 libjin/Tools/CSV/CSV.cpp                     |  0
 libjin/Tools/CSV/CSV.h                       |  1 +
 libjin/Tools/Component/Component.h           | 30 +++++++++++++
 libjin/Tools/Component/GameObject.h          | 40 +++++++++++++++++
 libjin/Tools/EventMsgCenter/EventMsgCenter.h | 20 +++++++++
 libjin/Tools/EventMsgCenter/Events.h         | 20 +++++++++
 libjin/Tools/Json/Json.cpp                   |  0
 libjin/Tools/Json/Json.h                     |  1 +
 libjin/Tools/XML/XML.cpp                     |  0
 libjin/Tools/XML/XML.h                       |  1 +
 libjin/modules.h                             | 65 +++++++++++++++-------------
 test/01HelloWorld/main.cpp                   |  2 +-
 17 files changed, 168 insertions(+), 34 deletions(-)
 create mode 100644 libjin/Tools/CSV/CSV.cpp
 create mode 100644 libjin/Tools/CSV/CSV.h
 create mode 100644 libjin/Tools/Component/Component.h
 create mode 100644 libjin/Tools/Component/GameObject.h
 create mode 100644 libjin/Tools/EventMsgCenter/Events.h
 create mode 100644 libjin/Tools/Json/Json.cpp
 create mode 100644 libjin/Tools/Json/Json.h
 create mode 100644 libjin/Tools/XML/XML.cpp
 create mode 100644 libjin/Tools/XML/XML.h

diff --git a/build/libjin/libjin.vcxproj b/build/libjin/libjin.vcxproj
index a1ba5df..aa8e12e 100644
--- a/build/libjin/libjin.vcxproj
+++ b/build/libjin/libjin.vcxproj
@@ -103,6 +103,8 @@
     <ClInclude Include="..\..\libjin\Thread\Thread.h" />
     <ClInclude Include="..\..\libjin\Tilemap\Tilemap.h" />
     <ClInclude Include="..\..\libjin\Time\Timer.h" />
+    <ClInclude Include="..\..\libjin\Tools\Component\Component.h" />
+    <ClInclude Include="..\..\libjin\Tools\Component\GameObject.h" />
     <ClInclude Include="..\..\libjin\Tools\EventMsgCenter\EventMsgCenter.h" />
     <ClInclude Include="..\..\libjin\UI\UI.h" />
     <ClInclude Include="..\..\libjin\Utils\endian.h" />
diff --git a/build/libjin/libjin.vcxproj.filters b/build/libjin/libjin.vcxproj.filters
index 0f3b2e4..7e1e033 100644
--- a/build/libjin/libjin.vcxproj.filters
+++ b/build/libjin/libjin.vcxproj.filters
@@ -76,6 +76,9 @@
     <Filter Include="Time">
       <UniqueIdentifier>{53e06a65-a5ba-41d8-a1f6-6fb5680207ba}</UniqueIdentifier>
     </Filter>
+    <Filter Include="Tools\Component">
+      <UniqueIdentifier>{5685d2ab-4373-4b9c-9cd1-634b1916b09c}</UniqueIdentifier>
+    </Filter>
   </ItemGroup>
   <ItemGroup>
     <ClCompile Include="..\..\libjin\3rdparty\GLee\GLee.c">
@@ -340,6 +343,12 @@
     <ClInclude Include="..\..\libjin\Common\Singleton.hpp">
       <Filter>Common</Filter>
     </ClInclude>
+    <ClInclude Include="..\..\libjin\Tools\Component\GameObject.h">
+      <Filter>Tools\Component</Filter>
+    </ClInclude>
+    <ClInclude Include="..\..\libjin\Tools\Component\Component.h">
+      <Filter>Tools\Component</Filter>
+    </ClInclude>
   </ItemGroup>
   <ItemGroup>
     <None Include="..\..\libjin\README.md" />
diff --git a/libjin/Core/Game.cpp b/libjin/Core/Game.cpp
index 06537c7..ffd8015 100644
--- a/libjin/Core/Game.cpp
+++ b/libjin/Core/Game.cpp
@@ -25,6 +25,7 @@ namespace core
         _running = true;
         Event e;
         int previous = getMilliSecond();
+        float dt = MS_PER_UPDATE / 1000.0f;
         while (_running)
         {
             while (jin::input::pollEvent(&e))
@@ -32,14 +33,18 @@ namespace core
                 SAFECALL(_onEvent, &e);
                 if (!_running) goto stoploop;
             }
-            SAFECALL(_onUpdate);
+            SAFECALL(_onUpdate, dt);
             SAFECALL(_onDraw);
             wnd->swapBuffers();
             const int current = getMilliSecond();
+            dt = (current - previous) / 1000.0f;
             const int wait = MS_PER_UPDATE - (current - previous);
             previous += MS_PER_UPDATE;
             if (wait > 0)
+            {
                 sleep(wait);
+                dt = MS_PER_UPDATE / 1000.0f;
+            }
             else
                 previous = current;
         }
diff --git a/libjin/Core/Game.h b/libjin/Core/Game.h
index 31825ba..090e7c6 100644
--- a/libjin/Core/Game.h
+++ b/libjin/Core/Game.h
@@ -17,7 +17,7 @@ namespace core
     public:
 
         typedef void(*onEvent)(jin::input::Event* e);
-        typedef void(*onUpdate)();
+        typedef void(*onUpdate)(float dt);
         typedef void(*onDraw)();
 
         struct Setting : SettingBase
diff --git a/libjin/Graphics/Drawable.h b/libjin/Graphics/Drawable.h
index c05d8a4..0b96379 100644
--- a/libjin/Graphics/Drawable.h
+++ b/libjin/Graphics/Drawable.h
@@ -8,6 +8,7 @@ namespace jin
 {
 namespace graphics
 {
+
     class Drawable
     {
     public:
@@ -51,6 +52,7 @@ namespace graphics
         float* vertCoord;
 
     };
+
 } // render
 } // jin
 
diff --git a/libjin/Tools/CSV/CSV.cpp b/libjin/Tools/CSV/CSV.cpp
new file mode 100644
index 0000000..e69de29
diff --git a/libjin/Tools/CSV/CSV.h b/libjin/Tools/CSV/CSV.h
new file mode 100644
index 0000000..6f70f09
--- /dev/null
+++ b/libjin/Tools/CSV/CSV.h
@@ -0,0 +1 @@
+#pragma once
diff --git a/libjin/Tools/Component/Component.h b/libjin/Tools/Component/Component.h
new file mode 100644
index 0000000..12c347a
--- /dev/null
+++ b/libjin/Tools/Component/Component.h
@@ -0,0 +1,30 @@
+#ifndef __JIN_TOOLS_COMPONENT_H
+#define __JIN_TOOLS_COMPONENT_H
+#include "../../modules.h"
+#if JIN_MODULES_TOOLS && JIN_TOOLS_COMPONENT
+
+namespace jin
+{
+namespace tools
+{
+
+    class GameObject;
+
+    class Component
+    {
+    public:
+        Component(GameObject* obj)
+            : gameObject(obj)
+        {}
+
+        virtual void update(float dt) = 0;
+
+    private: 
+        GameObject* gameObject;
+    };
+
+} // tools 
+} // jin
+
+#endif // JIN_MODULES_TOOLS && JIN_TOOLS_COMPONENT
+#endif // __JIN_TOOLS_COMPONENT_H
\ No newline at end of file
diff --git a/libjin/Tools/Component/GameObject.h b/libjin/Tools/Component/GameObject.h
new file mode 100644
index 0000000..aac9e6b
--- /dev/null
+++ b/libjin/Tools/Component/GameObject.h
@@ -0,0 +1,40 @@
+#ifndef __JIN_TOOLS_GAMEOBJECT_H
+#define __JIN_TOOLS_GAMEOBJECT_H
+#include "../../modules.h"
+#if JIN_MODULES_TOOLS && JIN_TOOLS_COMPONENT
+
+#include <vector>
+#include "Component.h"
+
+namespace jin
+{
+namespace tools
+{
+
+    class GameObject
+    {
+    public: 
+
+        GameObject()
+            : components()
+        {
+        }
+
+        virtual void update(float dt)
+        {
+            for each (Component* component in components)
+                component->update(dt);
+        }
+
+        virtual void draw() = 0;
+
+    protected:
+
+        std::vector<Component*> components;
+    };
+
+} // tools
+} // jin
+
+#endif // JIN_MODULES_TOOLS && JIN_TOOLS_COMPONENT
+#endif // __JIN_TOOLS_GAMEOBJECT_H
\ No newline at end of file
diff --git a/libjin/Tools/EventMsgCenter/EventMsgCenter.h b/libjin/Tools/EventMsgCenter/EventMsgCenter.h
index e69de29..a679f06 100644
--- a/libjin/Tools/EventMsgCenter/EventMsgCenter.h
+++ b/libjin/Tools/EventMsgCenter/EventMsgCenter.h
@@ -0,0 +1,20 @@
+#ifndef __JIN_TOOLS_EVENTMSGCENTER_H
+#define __JIN_TOOLS_EVENTMSGCENTER_H
+#include "../../modules.h"
+#if JIN_MODULES_TOOLS && JIN_TOOLS_EVENTMSGCENTER
+
+namespace jin
+{
+namespace tools
+{
+
+    class EventMSGCenter
+    {
+
+    };
+
+} // tools 
+} // jin
+
+#endif // JIN_MODULES_TOOLS && JIN_TOOLS_EVENTMSGCENTER
+#endif // __JIN_TOOLS_EVENTMSGCENTER_H
\ No newline at end of file
diff --git a/libjin/Tools/EventMsgCenter/Events.h b/libjin/Tools/EventMsgCenter/Events.h
new file mode 100644
index 0000000..698dfbc
--- /dev/null
+++ b/libjin/Tools/EventMsgCenter/Events.h
@@ -0,0 +1,20 @@
+#ifndef __JIN_TOOLS_EVENTS_H
+#define __JIN_TOOLS_EVENTS_H
+#include "../../modules.h"
+#if JIN_MODULES_TOOLS && JIN_TOOLS_EVENTMSGCENTER
+
+namespace jin
+{
+namespace tools
+{
+
+    enum Event
+    {
+
+    };
+
+} // tools 
+} // jin
+
+#endif // JIN_MODULES_TOOLS && JIN_TOOLS_EVENTMSGCENTER
+#endif // __JIN_TOOLS_EVENTS_H
\ No newline at end of file
diff --git a/libjin/Tools/Json/Json.cpp b/libjin/Tools/Json/Json.cpp
new file mode 100644
index 0000000..e69de29
diff --git a/libjin/Tools/Json/Json.h b/libjin/Tools/Json/Json.h
new file mode 100644
index 0000000..6f70f09
--- /dev/null
+++ b/libjin/Tools/Json/Json.h
@@ -0,0 +1 @@
+#pragma once
diff --git a/libjin/Tools/XML/XML.cpp b/libjin/Tools/XML/XML.cpp
new file mode 100644
index 0000000..e69de29
diff --git a/libjin/Tools/XML/XML.h b/libjin/Tools/XML/XML.h
new file mode 100644
index 0000000..6f70f09
--- /dev/null
+++ b/libjin/Tools/XML/XML.h
@@ -0,0 +1 @@
+#pragma once
diff --git a/libjin/modules.h b/libjin/modules.h
index 9db11e7..c117ef7 100644
--- a/libjin/modules.h
+++ b/libjin/modules.h
@@ -4,37 +4,40 @@
 * ����ģ�����ģ��ı��룬����Ҫģ��رղ�����
 */
 
-#define JIN_MODULES_AUDIO      1
-#define JIN_AUDIO_SDLAUDIO     1
-#define JIN_AUDIO_OPENAL       1
-
-#define JIN_MODULES_RENDER     1
-
-#define JIN_MODULES_DEBUG      1
-
-#define JIN_MODULES_FILESYSTEM 1 
-
-#define JIN_MODULES_INPUT      1 
-#define JIN_INPUT_SDL          1
-
-#define JIN_MODULES_MATH       1 
-
-#define JIN_MODULES_NET        1 
-
-#define JIN_MODULES_PHYSICS    1 
-#define JIN_PHYSICS_BOX2D      1
-#define JIN_PHYSICS_NEWTON     1
-
-#define JIN_MODULES_TILEMAP    1
-
-#define JIN_MODULES_UI         1
-
-#define JIN_MODULES_TOOLS      1
-
-#define JIN_MODULES_THREAD     1
-
-#define JIN_MODULES_TIME       1
-#define JIN_TIME_SDL           1
+#define JIN_MODULES_AUDIO        1
+#define JIN_AUDIO_SDLAUDIO       1
+#define JIN_AUDIO_OPENAL         1
+                                 
+#define JIN_MODULES_RENDER       1
+                                 
+#define JIN_MODULES_DEBUG        1
+                                 
+#define JIN_MODULES_FILESYSTEM   1 
+                                 
+#define JIN_MODULES_INPUT        1 
+#define JIN_INPUT_SDL            1
+                                 
+#define JIN_MODULES_MATH         1 
+                                 
+#define JIN_MODULES_NET          1 
+                                 
+#define JIN_MODULES_PHYSICS      1 
+#define JIN_PHYSICS_BOX2D        1
+#define JIN_PHYSICS_NEWTON       1
+                                 
+#define JIN_MODULES_TILEMAP      1
+                                 
+#define JIN_MODULES_UI           1
+                                 
+#define JIN_MODULES_TOOLS        1
+#define JIN_TOOLS_COMPONENT      1
+#define JIN_TOOLS_EVENTMSGCENTER 1
+#define JIN_TOOLS_XML            1
+
+#define JIN_MODULES_THREAD       1
+                                 
+#define JIN_MODULES_TIME         1
+#define JIN_TIME_SDL             1
 
 /*
 * ����Debug
diff --git a/test/01HelloWorld/main.cpp b/test/01HelloWorld/main.cpp
index fa81918..cf6036b 100644
--- a/test/01HelloWorld/main.cpp
+++ b/test/01HelloWorld/main.cpp
@@ -12,7 +12,7 @@ void onEvent(jin::input::Event* e)
         game->stop();
 }
 
-void onUpdate()
+void onUpdate(float dt)
 {
 
 }
-- 
cgit v1.1-26-g67d0