Commits

Anonymous committed 381729c

game-test update

Comments (0)

Files changed (4)

 		Release|Any CPU = Release|Any CPU
 	EndGlobalSection
 	GlobalSection(ProjectConfigurationPlatforms) = postSolution
-		{42AE9267-6A8A-49AC-8EFE-A9DA2BFF6546}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
-		{42AE9267-6A8A-49AC-8EFE-A9DA2BFF6546}.Debug|Any CPU.Build.0 = Debug|Any CPU
+		{42AE9267-6A8A-49AC-8EFE-A9DA2BFF6546}.Debug|Any CPU.ActiveCfg = Debug|x86
+		{42AE9267-6A8A-49AC-8EFE-A9DA2BFF6546}.Debug|Any CPU.Build.0 = Debug|x86
 		{42AE9267-6A8A-49AC-8EFE-A9DA2BFF6546}.Release|Any CPU.ActiveCfg = Release|Any CPU
 		{42AE9267-6A8A-49AC-8EFE-A9DA2BFF6546}.Release|Any CPU.Build.0 = Release|Any CPU
-		{936F2A1E-54B3-45F2-8627-9447543049D2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
-		{936F2A1E-54B3-45F2-8627-9447543049D2}.Debug|Any CPU.Build.0 = Debug|Any CPU
+		{936F2A1E-54B3-45F2-8627-9447543049D2}.Debug|Any CPU.ActiveCfg = Debug|x86
+		{936F2A1E-54B3-45F2-8627-9447543049D2}.Debug|Any CPU.Build.0 = Debug|x86
 		{936F2A1E-54B3-45F2-8627-9447543049D2}.Release|Any CPU.ActiveCfg = Release|Any CPU
 		{936F2A1E-54B3-45F2-8627-9447543049D2}.Release|Any CPU.Build.0 = Release|Any CPU
-		{5480F275-D449-4DBA-9246-1A77F4875E23}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
-		{5480F275-D449-4DBA-9246-1A77F4875E23}.Debug|Any CPU.Build.0 = Debug|Any CPU
+		{5480F275-D449-4DBA-9246-1A77F4875E23}.Debug|Any CPU.ActiveCfg = Debug|x86
+		{5480F275-D449-4DBA-9246-1A77F4875E23}.Debug|Any CPU.Build.0 = Debug|x86
 		{5480F275-D449-4DBA-9246-1A77F4875E23}.Release|Any CPU.ActiveCfg = Release|Any CPU
 		{5480F275-D449-4DBA-9246-1A77F4875E23}.Release|Any CPU.Build.0 = Release|Any CPU
-		{750A85EA-D5EE-48E8-9DA2-048A56C0984D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
-		{750A85EA-D5EE-48E8-9DA2-048A56C0984D}.Debug|Any CPU.Build.0 = Debug|Any CPU
+		{750A85EA-D5EE-48E8-9DA2-048A56C0984D}.Debug|Any CPU.ActiveCfg = Debug|x86
+		{750A85EA-D5EE-48E8-9DA2-048A56C0984D}.Debug|Any CPU.Build.0 = Debug|x86
 		{750A85EA-D5EE-48E8-9DA2-048A56C0984D}.Release|Any CPU.ActiveCfg = Release|Any CPU
 		{750A85EA-D5EE-48E8-9DA2-048A56C0984D}.Release|Any CPU.Build.0 = Release|Any CPU
 	EndGlobalSection

SharpHammer.v11.suo

Binary file modified.

UnitTest/Program.cs

 using System;
 using SharpHammer;
+using Assembly = System.Reflection.Assembly;
+using Path = System.IO.Path;
 
 namespace UnitTest
 {
 	{
 		static int prev_x = 0;
 		static int prev_y = 0;
+		static camera g_cam;
+		static IntPtr g_timer;
+		static uint g_scene;
 
 		static void updateCamera()
 		{
+			const float dt = .005f;
+			float ft;
+			unsafe {
+				timer* tm = (timer*)g_timer.ToPointer();
+				ft = tm->dt;
+			}
+			float move = 5f * ft;
+
 			int mx = 0, my = 0;
 			uint mousekeys = 0;
 			bool rm = engine.input_get_mouse(ref mx, ref my, ref mousekeys);
 				(my >= 0 && my < engine.app_get_wndheight())) {
 					float dx = (float)(mx - prev_x);
 					float dy = (float)(my - prev_y);
-					if (Math.Abs(dx) > .001f) {
+					if (Math.Abs(dx) > .001f)
+						engine.cam_yaw(ref g_cam, dx * dt);
+					if (Math.Abs(dy) > .001f)
+						engine.cam_pitch(ref g_cam, dy * dt);
 
-					}
+					if (engine.input_get_kbhit(input_key.INPUT_KEY_LSHIFT) ||
+					    engine.input_get_kbhit(input_key.INPUT_KEY_RSHIFT))
+						move *= 5.0f;
+					if (engine.input_get_kbhit(input_key.INPUT_KEY_W) ||
+					    engine.input_get_kbhit(input_key.INPUT_KEY_UP))
+						engine.cam_fwd(ref g_cam, move);
+					if (engine.input_get_kbhit(input_key.INPUT_KEY_S) ||
+					    engine.input_get_kbhit(input_key.INPUT_KEY_DOWN))
+						engine.cam_fwd(ref g_cam, -move);
+					if (engine.input_get_kbhit(input_key.INPUT_KEY_A) ||
+					    engine.input_get_kbhit(input_key.INPUT_KEY_LEFT))
+						engine.cam_strafe(ref g_cam, -move);
+					if (engine.input_get_kbhit(input_key.INPUT_KEY_RIGHT) ||
+					    engine.input_get_kbhit(input_key.INPUT_KEY_UP))
+						engine.cam_strafe(ref g_cam, move);
+
+					engine.cam_update(ref g_cam);
 				}
-
+				prev_x = mx;
+				prev_y = my;
 			}
 		}
 
 		static void onUpdate()
 		{
 			engine.input_update();
+			updateCamera();
+			engine.eng_update();
+		}
 
+		static void onKeypress(string wnd_name, byte charcode, uint vkeycode)
+		{
+			engine.eng_send_guimsgs(charcode, vkeycode);
+		}
+
+		static void onActivate(string wnd_name, bool active)
+		{
+			if (active)
+				engine.eng_resume();
+			else
+				engine.eng_pause();
+		}
+
+		static void onResize(string wnd_name, uint width, uint height)
+		{
+			engine.cam_set_viewsize(ref g_cam, width, height);
+		}
+
+		static bool load_props()
+		{
+			set_datadir();
+			Vec4 pos = new Vec4(0f, 1f, 0f, 0f);
+			Vec4 target = new Vec4(0f, 1f, 1f, 0f);
+			engine.cam_init(ref g_cam, ref pos, ref target, .1f, 1000f, 1.048f);
+
+			g_timer = core.timer_add(true);
+			
+			g_scene = engine.scn_create_scene("test");
+			if (g_scene == 0)
+				return false;
+			engine.scn_setactive(g_scene);
+			engine.scn_setcam(ref g_cam);
+
+			engine.sct_runfile("test5.lua");
+			return true;
+		}
+
+		static void set_datadir()
+		{
+			var dir = Path.GetDirectoryName(
+				Assembly.GetExecutingAssembly().Location);
+			dir += "/data";
+			core.io_addvdir(dir, true);
 		}
 
 		private static void Main(string[] args)
 		{
-			core.core_init(true);
-			core.log_outputconsole(true);
-			var param = engine.app_defaultconfig();
-			engine.app_init("dark-hammer:test", param, IntPtr.Zero);
-			engine.eng_init(param);
+			result_t r = core.core_init(true);
+			if (r != result_t.RET_OK) {
+				Console.WriteLine("failed to init core. result: {0}", 
+					r.ToString());
+			}
+			r = core.log_outputconsole(true);
+			if (r != result_t.RET_OK) {
+				Console.WriteLine("failed to set console log output. result: {0}",
+					r.ToString());
+			}
+
+			//var param = engine.app_load_config("conf.json");
+			IntPtr param = engine.app_defaultconfig();
+
+			if (param == IntPtr.Zero)
+				Console.WriteLine("failed to load default config. result: {0}",
+					r.ToString());
+
+			r = engine.app_init("dark-hammer:test", param, IntPtr.Zero);
+			if (r != result_t.RET_OK) {
+				Console.WriteLine("failed to init app. result: {0}",
+					r.ToString());
+			}
+			r = engine.eng_init(param);
+			if (r != result_t.RET_OK) {
+				Console.WriteLine("failed to init engine. result: {0}",
+					r.ToString());
+			}
+			load_props();
 			engine.app_set_updatefunc(onUpdate);
-			//	app_set_keypressfunc(keypress_callback);
-			//	app_set_activefunc(activate_callback);
-			//	gfx_set_debug_renderfunc(debug_view_callback);
+			engine.app_set_keypressfunc(onKeypress);
+			engine.app_set_activefunc(onActivate);
+			engine.app_set_resizefunc(onResize);
+
 			engine.app_show_window(null);
 			engine.app_update();
 

UnitTest/UnitTest.csproj

     <WarningLevel>4</WarningLevel>
     <UseVSHostingProcess>true</UseVSHostingProcess>
     <Prefer32Bit>false</Prefer32Bit>
+    <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
   </PropertyGroup>
   <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
     <PlatformTarget>AnyCPU</PlatformTarget>
     <ErrorReport>prompt</ErrorReport>
     <WarningLevel>4</WarningLevel>
     <Prefer32Bit>false</Prefer32Bit>
+    <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x86'">
+    <PlatformTarget>x86</PlatformTarget>
+    <OutputPath>bin\x86\Debug\</OutputPath>
+    <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
+    <DefineConstants>TRACE</DefineConstants>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x86'">
+    <PlatformTarget>x86</PlatformTarget>
+    <OutputPath>bin\x86\Release\</OutputPath>
+    <Optimize>true</Optimize>
+    <DefineConstants>TRACE</DefineConstants>
   </PropertyGroup>
   <ItemGroup>
     <Reference Include="System" />