Browse Source

Windows should mostly work now, except for examples project

Ivan Safrin 13 years ago
parent
commit
ebac791192

+ 118 - 4
CMake/FindBullet.cmake

@@ -20,6 +20,13 @@ SET(BULLET_SEARCH_PATHS
   SET(BULLETSOFTBODY "BulletSoftBody")
   SET(BULLETMULTITHREADED "BulletMultiThreaded")
 
+  SET(BULLETDYNAMICS_DEBUG "BulletDynamics_d")
+  SET(BULLETCOLLISION_DEBUG "BulletCollision_d")
+  SET(BULLETMATH_DEBUG "LinearMath_d")
+  SET(BULLETSOFTBODY_DEBUG "BulletSoftBody_d")
+  SET(BULLETMULTITHREADED_DEBUG "BulletMultiThreaded_d")
+
+
 FIND_PATH(BULLET_INCLUDE_DIR NAMES btBulletCollisionCommon.h
 	HINTS
 	NO_DEFAULT_PATH
@@ -133,15 +140,122 @@ IF(NOT LIBBULLETMULTITHREADED)
     MESSAGE ("WARNING: Could not find Bullet MultiThreaded - depending targets will be disabled.")
 ENDIF(NOT LIBBULLETMULTITHREADED)
 
+# -------
+
+FIND_LIBRARY(LIBBULLETDYNAMICS_DEBUG
+  NAMES 
+  ${BULLETDYNAMICS_DEBUG}
+	HINTS
+	NO_DEFAULT_PATH
+	NO_CMAKE_ENVIRONMENT_PATH
+	NO_CMAKE_SYSTEM_PATH
+	NO_SYSTEM_ENVIRONMENT_PATH
+	NO_CMAKE_PATH
+	CMAKE_FIND_FRAMEWORK NEVER
+	$ENV{BULLETDIR}
+	$ENV{BULLET_PATH}
+	PATH_SUFFIXES lib lib64 win32/Dynamic_Release "Win32/${MSVC_YEAR_NAME}/x64/Release" "Win32/${MSVC_YEAR_NAME}/Win32/Release"
+	PATHS ${BULLET_SEARCH_PATHS}
+)
+
+IF(NOT LIBBULLETDYNAMICS_DEBUG)
+    MESSAGE ("WARNING: Could not find Bullet Dynamics Debug - depending targets will be disabled.")
+ENDIF(NOT LIBBULLETDYNAMICS_DEBUG)
+
+
+FIND_LIBRARY(LIBBULLETCOLLISION_DEBUG
+  NAMES 
+  ${BULLETCOLLISION_DEBUG}
+	HINTS
+	NO_DEFAULT_PATH
+	NO_CMAKE_ENVIRONMENT_PATH
+	NO_CMAKE_SYSTEM_PATH
+	NO_SYSTEM_ENVIRONMENT_PATH
+	NO_CMAKE_PATH
+	CMAKE_FIND_FRAMEWORK NEVER
+	$ENV{BULLETDIR}
+	$ENV{BULLET_PATH}
+	PATH_SUFFIXES lib lib64 win32/Dynamic_Release "Win32/${MSVC_YEAR_NAME}/x64/Release" "Win32/${MSVC_YEAR_NAME}/Win32/Release"
+	PATHS ${BULLET_SEARCH_PATHS}
+)
+
+IF(NOT LIBBULLETCOLLISION_DEBUG)
+    MESSAGE ("WARNING: Could not find Bullet Collision Debug - depending targets will be disabled.")
+ENDIF(NOT LIBBULLETCOLLISION_DEBUG)
+
+FIND_LIBRARY(LIBBULLETMATH_DEBUG
+  NAMES 
+  ${BULLETMATH_DEBUG}
+	HINTS
+	NO_DEFAULT_PATH
+	NO_CMAKE_ENVIRONMENT_PATH
+	NO_CMAKE_SYSTEM_PATH
+	NO_SYSTEM_ENVIRONMENT_PATH
+	NO_CMAKE_PATH
+	CMAKE_FIND_FRAMEWORK NEVER
+	$ENV{BULLETDIR}
+	$ENV{BULLET_PATH}
+	PATH_SUFFIXES lib lib64 win32/Dynamic_Release "Win32/${MSVC_YEAR_NAME}/x64/Release" "Win32/${MSVC_YEAR_NAME}/Win32/Release"
+	PATHS ${BULLET_SEARCH_PATHS}
+)
+
+IF(NOT LIBBULLETMATH_DEBUG)
+    MESSAGE ("WARNING: Could not find Bullet Math Debug - depending targets will be disabled.")
+ENDIF(NOT LIBBULLETMATH_DEBUG)
+
+FIND_LIBRARY(LIBBULLETSOFTBODY_DEBUG
+  NAMES 
+  ${BULLETSOFTBODY_DEBUG}
+	HINTS
+	NO_DEFAULT_PATH
+	NO_CMAKE_ENVIRONMENT_PATH
+	NO_CMAKE_SYSTEM_PATH
+	NO_SYSTEM_ENVIRONMENT_PATH
+	NO_CMAKE_PATH
+	CMAKE_FIND_FRAMEWORK NEVER
+	$ENV{BULLETDIR}
+	$ENV{BULLET_PATH}
+	PATH_SUFFIXES lib lib64 win32/Dynamic_Release "Win32/${MSVC_YEAR_NAME}/x64/Release" "Win32/${MSVC_YEAR_NAME}/Win32/Release"
+	PATHS ${BULLET_SEARCH_PATHS}
+)
+
+IF(NOT LIBBULLETSOFTBODY_DEBUG)
+    MESSAGE ("WARNING: Could not find Bullet SoftBody Debug - depending targets will be disabled.")
+ENDIF(NOT LIBBULLETSOFTBODY_DEBUG)
+
+
+FIND_LIBRARY(LIBBULLETMULTITHREADED_DEBUG
+  NAMES 
+  ${BULLETMULTITHREADED_DEBUG}
+	HINTS
+	NO_DEFAULT_PATH
+	NO_CMAKE_ENVIRONMENT_PATH
+	NO_CMAKE_SYSTEM_PATH
+	NO_SYSTEM_ENVIRONMENT_PATH
+	NO_CMAKE_PATH
+	CMAKE_FIND_FRAMEWORK NEVER
+	$ENV{BULLETDIR}
+	$ENV{BULLET_PATH}
+	PATH_SUFFIXES lib lib64 win32/Dynamic_Release "Win32/${MSVC_YEAR_NAME}/x64/Release" "Win32/${MSVC_YEAR_NAME}/Win32/Release"
+	PATHS ${BULLET_SEARCH_PATHS}
+)
+
+IF(NOT LIBBULLETMULTITHREADED_DEBUG)
+    MESSAGE ("WARNING: Could not find Bullet MultiThreaded Debug - depending targets will be disabled.")
+ENDIF(NOT LIBBULLETMULTITHREADED_DEBUG)
+
+
 SET(BULLET_LIBRARIES ${LIBBULLETMULTITHREADED} ${LIBBULLETSOFTBODY} ${LIBBULLETDYNAMICS} ${LIBBULLETCOLLISION} ${LIBBULLETMATH})
 
-IF(BULLET_INCLUDE_DIR AND BULLET_LIBRARIES)
+SET(BULLET_LIBRARIES_DEBUG ${LIBBULLETMULTITHREADED_DEBUG} ${LIBBULLETSOFTBODY_DEBUG} ${LIBBULLETDYNAMICS_DEBUG} ${LIBBULLETCOLLISION_DEBUG} ${LIBBULLETMATH_DEBUG})
+
+IF(BULLET_INCLUDE_DIR AND BULLET_LIBRARIES AND BULLET_LIBRARIES_DEBUG)
   SET(BULLET_FOUND TRUE)
-ENDIF(BULLET_INCLUDE_DIR AND BULLET_LIBRARIES)
+ENDIF(BULLET_INCLUDE_DIR AND BULLET_LIBRARIES AND BULLET_LIBRARIES_DEBUG)
 
 # show the BULLET_INCLUDE_DIR and BULLET_LIBRARIES variables only in the advanced view
 IF(BULLET_FOUND)
-  MESSAGE ("Bullet found (${BULLET_INCLUDE_DIR}) (${BULLET_LIBRARIES})")
-  MARK_AS_ADVANCED(BULLET_INCLUDE_DIR BULLET_LIBRARIES )
+  MESSAGE ("Bullet found (${BULLET_INCLUDE_DIR}) (${BULLET_LIBRARIES}) (${BULLET_LIBRARIES_DEBUG})")
+  MARK_AS_ADVANCED(BULLET_INCLUDE_DIR BULLET_LIBRARIES BULLET_LIBRARIES_DEBUG)
 ENDIF(BULLET_FOUND)
 

+ 16 - 1
Core/Contents/Include/PolyString.h

@@ -186,6 +186,15 @@ namespace Polycode {
 			*/																															
 			const char *getDataWithEncoding(int encoding) const;
 			
+			/**
+			* Returns wide character data with the specified encoding. Currently the only supported encoding is String::ENCODING_UTF8
+			* @param encoding The encoding to use.
+			* @return A pointer to the data using specified encoding.
+			* @see getDataSizeWithEncoding()
+			*/																															
+			wchar_t *getWDataWithEncoding(int encoding);
+
+
 			/**
 			* Returns the size of the data with the specified encoding. Currently the only supported encoding is String::ENCODING_UTF8
 			* @param encoding The encoding to use.
@@ -201,11 +210,17 @@ namespace Polycode {
 			*/																																		
 			void setDataWithEncoding(char *data, int encoding);
 			
+
 			/**
 			* STL string version of the string.
 			*/																																					
 			std::string contents;
-						
+
+			/**
+			* STL string version of the string.
+			*/																																					
+			std::wstring w_contents;
+
 			/**
 			* UTF-8 encoding.
 			*/																																							

+ 2 - 0
Core/Contents/Include/PolyWinCore.h

@@ -225,6 +225,8 @@ public:
 
 		// NEED TO IMPLEMENT:
 
+		String executeExternalCommand(String command) { return "";}
+
 		void openURL(String url) {}
 		void setCursor(int cursorType){ }
 		void copyStringToClipboard(const String& str) { }

+ 13 - 0
Core/Contents/Source/PolyString.cpp

@@ -85,6 +85,19 @@ const char *String::getDataWithEncoding(int encoding) const {
 	}
 }
 
+wchar_t *String::getWDataWithEncoding(int encoding) {
+	switch(encoding) {
+		case ENCODING_UTF8: {
+			utf8toWStr(w_contents, contents);
+			return (wchar_t *)w_contents.c_str();
+		}
+		break;
+		default:
+			return NULL;
+	}
+}
+
+
 void String::setDataWithEncoding(char *data, int encoding) {
 	switch(encoding) {
 		case ENCODING_UTF8: {

+ 23 - 6
Modules/Bindings/2DPhysics/CMakeLists.txt

@@ -52,15 +52,15 @@ TARGET_LINK_LIBRARIES(Physics2D
         ${VORBIS_LIBRARIES}
         ${VORBISFILE_LIBRARIES}
         ${EXTRA_LIBS})
-ELSE(APPLE)
-IF (MINGW)
-	SET(MINGW_EXTRA_LIBS ${ZLIB_LIBRARY})
-ENDIF(MINGW)
+ELSEIF(MSVC OR MINGW)
+
+	SET(WIN_EXTRA_LIBS ${ZLIB_LIBRARIES} opengl32 glu32 winmm ws2_32)
 
 TARGET_LINK_LIBRARIES(Physics2D
 	Polycore
 	${LUA_LIBRARY}
-	${BOX2D_RELEASE_LIBRARY}
+  optimized ${BOX2D_RELEASE_LIBRARY}
+  debug ${BOX2D_DEBUG_LIBRARY}
         ${OPENGL_LIBRARIES}
         ${OPENAL_LIBRARY}
         ${PNG_LIBRARIES}
@@ -70,7 +70,24 @@ TARGET_LINK_LIBRARIES(Physics2D
         ${VORBIS_LIBRARIES}
         ${VORBISFILE_LIBRARIES}
         ${EXTRA_LIBS}
-        ${MINGW_EXTRA_LIBS})
+        ${WIN_EXTRA_LIBS})
+
+ELSE(APPLE)
+
+TARGET_LINK_LIBRARIES(Physics2D
+	Polycore
+	${LUA_LIBRARY}
+        ${BOX2D_RELEASE_LIBRARY}
+        ${OPENGL_LIBRARIES}
+        ${OPENAL_LIBRARY}
+        ${PNG_LIBRARIES}
+        ${FREETYPE_LIBRARIES}
+        ${PHYSFS_LIBRARY}
+        ${OGG_LIBRARIES}
+        ${VORBIS_LIBRARIES}
+        ${VORBISFILE_LIBRARIES}
+        ${EXTRA_LIBS})
+          
 ENDIF(APPLE)
 
 IF(POLYCODE_INSTALL_FRAMEWORK)

+ 33 - 7
Modules/Bindings/3DPhysics/CMakeLists.txt

@@ -34,7 +34,7 @@ ADD_LIBRARY(Physics3D SHARED ${polycode3DPhysics_SRCS} ${polycode3DPhysics_HDRS}
 SET_SOURCE_FILES_PROPERTIES(Source/Physics3DLUA.cpp PROPERTIES GENERATED 1)
 SET_SOURCE_FILES_PROPERTIES(Include/Physics3DLUAWrappers.h PROPERTIES GENERATED 1)
 SET_SOURCE_FILES_PROPERTIES(Include/Physics3DLUA.h PROPERTIES GENERATED 1)
-ADD_DEPENDENCIES(Physics2D PolycodeLuaGenerate)
+ADD_DEPENDENCIES(Physics3D PolycodeLuaGenerate)
 
 SET(CMAKE_DEBUG_POSTFIX "_d")
 
@@ -57,15 +57,23 @@ TARGET_LINK_LIBRARIES(Physics3D
         ${VORBIS_LIBRARIES}
         ${VORBISFILE_LIBRARIES}
         ${EXTRA_LIBS})
-ELSE(APPLE)
-IF (MINGW)
-	SET(MINGW_EXTRA_LIBS ${ZLIB_LIBRARY})
-ENDIF(MINGW)
+
+ELSEIF(MSVC OR MINGW)
+	SET(WIN_EXTRA_LIBS ${ZLIB_LIBRARIES} opengl32 glu32 winmm ws2_32)
 
 TARGET_LINK_LIBRARIES(Physics3D
 	Polycore
 	${LUA_LIBRARY}
-	${BULLET_LIBRARIES}
+        optimized ${LIBBULLETMULTITHREADED}
+        optimized ${LIBBULLETSOFTBODY} 
+        optimized ${LIBBULLETDYNAMICS} 
+        optimized ${LIBBULLETCOLLISION}
+        optimized ${LIBBULLETMATH}            
+        debug ${LIBBULLETMULTITHREADED_DEBUG}
+        debug ${LIBBULLETSOFTBODY_DEBUG} 
+        debug ${LIBBULLETDYNAMICS_DEBUG} 
+        debug ${LIBBULLETCOLLISION_DEBUG}
+        debug ${LIBBULLETMATH_DEBUG}            
         ${OPENGL_LIBRARIES}
         ${OPENAL_LIBRARY}
         ${PNG_LIBRARIES}
@@ -75,7 +83,25 @@ TARGET_LINK_LIBRARIES(Physics3D
         ${VORBIS_LIBRARIES}
         ${VORBISFILE_LIBRARIES}
         ${EXTRA_LIBS}
-        ${MINGW_EXTRA_LIBS})
+        ${WIN_EXTRA_LIBS})
+
+ELSE(APPLE)
+
+TARGET_LINK_LIBRARIES(Physics3D
+	Polycore
+	${LUA_LIBRARY}	
+  ${BULLET_LIBRARIES}
+        ${OPENGL_LIBRARIES}
+        ${OPENAL_LIBRARY}
+        ${PNG_LIBRARIES}
+        ${FREETYPE_LIBRARIES}
+        ${PHYSFS_LIBRARY}
+        ${OGG_LIBRARIES}
+        ${VORBIS_LIBRARIES}
+        ${VORBISFILE_LIBRARIES}
+        ${EXTRA_LIBS})
+        
+        
 ENDIF(APPLE)
 
 

+ 41 - 14
Player/Contents/CMakeLists.txt

@@ -1,46 +1,49 @@
 INCLUDE(PolycodeIncludes)
     
+SET(CMAKE_DEBUG_POSTFIX "_d")
+
+IF(MSVC OR MINGW)
+
 INCLUDE_DIRECTORIES(
     ${LUA_INCLUDE_DIR}
     ${Polycode_SOURCE_DIR}/Bindings/Contents/LUA/Include
     Include
-    ../../Core/Contents/PolycodeView/Mac\ OS\ X/
+    ../../Core/Contents/PolycodeView/MSVC/
 )
 
-SET(CMAKE_DEBUG_POSTFIX "_d")
-
-IF(MSVC OR MINGW)
-
 SET(polycodeplayer_SRCS 
         Source/PolycodePlayer.cpp
         Source/PolycodeWindowsPlayer.cpp
-        Platform/Windows/main.cpp
+        Source/PolycodePlayerView.cpp
+        Platform/Windows/main.cpp        
     )
 
     SET(polycodeplayer_HDRS 
         Include/PolycodePlayer.h
         Include/PolycodeWindowsPlayer.h
+        Include/PolycodePlayerView.h
     )
   
     SET(polycodeplayerstandalone_SRCS 
         Source/PolycodePlayer.cpp
         Source/PolycodeWindowsPlayer.cpp
+        Source/PolycodePlayerView.cpp
         Platform/Windows/Standalone/main.cpp
     )
     SET(polycodeplayerstandalone_HDRS 
         Include/PolycodePlayer.h
         Include/PolycodeWindowsPlayer.h
+        Include/PolycodePlayerView.h        
     )
  
-    INCLUDE_DIRECTORIES(Include)
- 
-    ADD_EXECUTABLE(PolycodePlayer ${polycodeplayer_SRCS} ${polycodeplayer_HDRS})
-    ADD_EXECUTABLE(StandalonePlayer ${polycodeplayerstandalone_SRCS} ${polycodeplayerstandalone_HDRS})
+    ADD_EXECUTABLE(PolycodePlayer WIN32 ${polycodeplayer_SRCS} ${polycodeplayer_HDRS})
+    ADD_EXECUTABLE(StandalonePlayer WIN32 ${polycodeplayerstandalone_SRCS} ${polycodeplayerstandalone_HDRS})
     
 
     TARGET_LINK_LIBRARIES(PolycodePlayer 
         PolycodeLua 
-        Polycore 
+        Polycore
+        ${ZLIB_LIBRARIES}
         ${LUA_LIBRARY}
         ${OPENGL_LIBRARIES}
         ${OPENAL_LIBRARY}
@@ -50,12 +53,16 @@ SET(polycodeplayer_SRCS
         ${OGG_LIBRARY}
         ${VORBIS_LIBRARY}
         ${VORBISFILE_LIBRARY}
-        ${SDL_LIBRARY}
+        opengl32
+        glu32
+        winmm
+        ws2_32
      )
 
     TARGET_LINK_LIBRARIES(StandalonePlayer 
         PolycodeLua 
         Polycore 
+        ${ZLIB_LIBRARIES}
         ${LUA_LIBRARY}
         ${OPENGL_LIBRARIES}
         ${OPENAL_LIBRARY}
@@ -64,11 +71,23 @@ SET(polycodeplayer_SRCS
         ${PHYSFS_LIBRARY}
         ${OGG_LIBRARY}
         ${VORBIS_LIBRARY}
-        ${VORBISFILE_LIBRARY}
-        ${SDL_LIBRARY}
+        ${VORBISFILE_LIBRARY} 
+        opengl32
+        glu32
+        winmm
+        ws2_32   
      )
 
 ELSEIF(APPLE)
+
+   
+INCLUDE_DIRECTORIES(
+    ${LUA_INCLUDE_DIR}
+    ${Polycode_SOURCE_DIR}/Bindings/Contents/LUA/Include
+    Include
+    ../../Core/Contents/PolycodeView/Mac\ OS\ X/
+)
+
     SET(polycodeplayer_SRCS 
         Source/PolycodePlayer.cpp
         Source/PolycodeCocoaPlayer.mm
@@ -205,6 +224,14 @@ foreach(xib ${PolycodePlayerStandalone_XIBS})
 endforeach()
 ELSE(MSVC OR MINGW)
 
+   
+INCLUDE_DIRECTORIES(
+    ${LUA_INCLUDE_DIR}
+    ${Polycode_SOURCE_DIR}/Bindings/Contents/LUA/Include
+    Include
+    ../../Core/Contents/PolycodeView/Linux/
+)
+
  SET(polycodeplayer_SRCS 
         Source/PolycodePlayer.cpp
         Source/PolycodeLinuxPlayer.cpp

+ 23 - 0
Player/Contents/Include/PolycodePlayerView.h

@@ -0,0 +1,23 @@
+#pragma once
+
+#include <Polycode.h>
+#include <PolyWinCore.h>
+#include <PolycodePlayer.h>
+#include <windows.h>
+
+using namespace Polycode;
+
+namespace Polycode {
+
+class _PolyExport PolycodePlayerView : public PolycodeViewBase, public EventHandler {
+public:
+	PolycodePlayerView(bool standaloneMode, HINSTANCE hInstance, int nCmdShow, LPCTSTR windowTitle);
+	~PolycodePlayerView();
+
+	void handleEvent(Event *event);
+
+	HWND consoleTextArea;
+	HWND hwnd;
+};
+
+}

BIN
Player/Contents/Include/player_icon.ico


+ 7 - 0
Player/Contents/Include/resource.h

@@ -0,0 +1,7 @@
+#define IDR_MYMENU 101
+#define IDI_MYICON 201
+
+#define ID_FILE_EXIT 9001
+#define ID_SHOW_CONSOLE 9002
+#define ID_FILE_OPEN 9003
+

+ 75 - 8
Player/Contents/Platform/Windows/Standalone/main.cpp

@@ -1,11 +1,78 @@
-#include "Polycode.h"
-#include "PolycodeView.h"
-#include "PolycodeLinuxPlayer.h"
 
-int main(int argc, char *argv[]) {
-	PolycodeView *view = new PolycodeView("Polycode Player");
-	PolycodeLinuxPlayer *player = new PolycodeLinuxPlayer(view, "main.polyapp", false);
+#include "PolycodeWindowsPlayer.h"
+#include <Polycode.h>
+#include "PolycodePlayerView.h"
+#include "windows.h"
+#include "resource.h"
+
+
+using namespace Polycode;
+
+extern Win32Core *core;
+
+void wtoc(char* Dest, TCHAR* Source, int SourceSize)
+{
+for(int i = 0; i < SourceSize; ++i)
+Dest[i] = (char)Source[i];
+}
+
+int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
+{
+	
+	String args = String(GetCommandLineW());
+	String fileName;
+	for(int i=0; i < args.length(); i++) {
+		if(args[i] != '\"')
+			fileName += args.substr(i, 1);
+		if(args[i] == '\"' && i != args.length()-1)
+			fileName = "";
+	}
+
+	if(fileName == " ")
+		fileName = "";
+
+	if(fileName.length() > 1)  {
+		fileName = fileName.replace(":", "");
+		fileName = fileName.replace("\\", "/");
+		fileName = fileName.substr(1, fileName.length() - 1);
+
+	}
+
+	char path[2049];
+	TCHAR tpath[2049];
+	GetModuleFileName(NULL, (LPWSTR)tpath, 2048);
+	wtoc(path, tpath, 2048);
+	
+	String basePath = path;
+	vector<String> cpts = basePath.split("\\");
+	String installPath = "";
+	for(int i=0; i < cpts.size() - 1; i++) {
+		installPath = installPath + cpts[i];
+		installPath += String("\\");
+	}
+	
+	SetCurrentDirectory(installPath.getWDataWithEncoding(String::ENCODING_UTF8));
+
+
+	PolycodePlayerView *view = new PolycodePlayerView(true, hInstance, nCmdShow, L"");
+	PolycodeWindowsPlayer *player = new PolycodeWindowsPlayer(view, "main.polyapp", false);
+
+	player->addEventListener(view, PolycodeDebugEvent::EVENT_ERROR);
+	player->addEventListener(view, PolycodeDebugEvent::EVENT_PRINT);
+
+
 	player->runPlayer();
-	while(player->Update()) {}
-	return 0;
+
+	core = (Win32Core*)player->getCore();
+
+	MSG Msg;
+
+		do {
+			if(PeekMessage(&Msg, NULL, 0,0,PM_REMOVE)) {
+				TranslateMessage(&Msg);
+				DispatchMessage(&Msg);
+			}
+		} while(player->Update());
+	
+	return Msg.wParam;
 }

+ 77 - 12
Player/Contents/Platform/Windows/main.cpp

@@ -1,15 +1,80 @@
-#include "Polycode.h"
-#include "PolycodeView.h"
-#include "PolycodeLinuxPlayer.h"
-
-int main(int argc, char *argv[]) {
-	PolycodeView *view = new PolycodeView("Polycode Player");
-	if(argc < 2) {
-		printf("Filename required!\n");
-		return 1;
+
+#include "PolycodeWindowsPlayer.h"
+#include <Polycode.h>
+#include "PolycodePlayerView.h"
+#include "windows.h"
+#include "resource.h"
+
+#define STANDALONE_MODE
+
+using namespace Polycode;
+
+
+extern Win32Core *core;
+
+void wtoc(char* Dest, TCHAR* Source, int SourceSize)
+{
+for(int i = 0; i < SourceSize; ++i)
+Dest[i] = (char)Source[i];
+}
+
+int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
+{
+	
+	String args = String(GetCommandLineW());
+	String fileName;
+	for(int i=0; i < args.length(); i++) {
+		if(args[i] != '\"')
+			fileName += args.substr(i, 1);
+		if(args[i] == '\"' && i != args.length()-1)
+			fileName = "";
+	}
+
+	if(fileName == " ")
+		fileName = "";
+
+	if(fileName.length() > 1)  {
+		fileName = fileName.replace(":", "");
+		fileName = fileName.replace("\\", "/");
+		fileName = fileName.substr(1, fileName.length() - 1);
+
+	}
+
+	char path[2049];
+	TCHAR tpath[2049];
+	GetModuleFileName(NULL, (LPWSTR)tpath, 2048);
+	wtoc(path, tpath, 2048);
+	
+	String basePath = path;
+	vector<String> cpts = basePath.split("\\");
+	String installPath = "";
+	for(int i=0; i < cpts.size() - 1; i++) {
+		installPath = installPath + cpts[i];
+		installPath += String("\\");
 	}
-	PolycodeLinuxPlayer *player = new PolycodeLinuxPlayer(view, argv[1], false);
+	
+	SetCurrentDirectory(installPath.getWDataWithEncoding(String::ENCODING_UTF8));
+
+
+	PolycodePlayerView *view = new PolycodePlayerView(false, hInstance, nCmdShow, L"Polycode Player");
+	PolycodeWindowsPlayer *player = new PolycodeWindowsPlayer(view, fileName.c_str(), false);
+
+	player->addEventListener(view, PolycodeDebugEvent::EVENT_ERROR);
+	player->addEventListener(view, PolycodeDebugEvent::EVENT_PRINT);
+
+
 	player->runPlayer();
-	while(player->Update()) {}
-	return 0;
+
+	core = (Win32Core*)player->getCore();
+
+	MSG Msg;
+
+		do {
+			if(PeekMessage(&Msg, NULL, 0,0,PM_REMOVE)) {
+				TranslateMessage(&Msg);
+				DispatchMessage(&Msg);
+			}
+		} while(player->Update());
+	
+	return Msg.wParam;
 }

+ 281 - 0
Player/Contents/Source/PolycodePlayerView.cpp

@@ -0,0 +1,281 @@
+
+#include "PolycodePlayerView.h"
+#include "resource.h"
+#include <Commdlg.h>
+
+using namespace Polycode;
+
+Win32Core *core = NULL;
+HWND consoleHwnd;
+
+LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
+{
+	int wmId, wmEvent;
+	PAINTSTRUCT ps;
+	HDC hdc;		
+	int nWidth, nHeight;
+	bool useDefault = false;
+
+	if(!core)
+		return DefWindowProc(hWnd, message, wParam, lParam);
+
+	switch (message)
+	{
+	case WM_SIZE:
+		nWidth = LOWORD(lParam); 
+		nHeight = HIWORD(lParam);
+		if(core)
+			core->getServices()->getRenderer()->Resize(nWidth, nHeight);
+	break;
+
+	case WM_MOUSEMOVE:
+		if(core)
+			core->handleMouseMove(lParam,wParam);
+	break;
+
+	case WM_MOUSEWHEEL:
+		if(core)
+			core->handleMouseWheel(lParam,wParam);
+	break;
+
+	case WM_LBUTTONDOWN:
+		if(core)
+			core->handleMouseDown(CoreInput::MOUSE_BUTTON1, lParam,wParam);
+	break;
+	case WM_LBUTTONUP:
+		if(core)
+			core->handleMouseUp(CoreInput::MOUSE_BUTTON1, lParam,wParam);
+	break;
+
+	case WM_RBUTTONDOWN:
+		if(core)
+			core->handleMouseDown(CoreInput::MOUSE_BUTTON2, lParam,wParam);
+	break;
+	case WM_RBUTTONUP:
+		if(core)
+			core->handleMouseUp(CoreInput::MOUSE_BUTTON2, lParam,wParam);
+	break;
+
+	case WM_TOUCH:
+		if(core) {
+			if(core->isMultiTouchEnabled()) {
+				core->handleTouchEvent(lParam, wParam);
+			}
+		}
+	break;
+
+	case WM_MBUTTONDOWN:
+		if(core)
+			core->handleMouseDown(CoreInput::MOUSE_BUTTON3, lParam,wParam);
+	break;
+	case WM_MBUTTONUP:
+		if(core)
+			core->handleMouseUp(CoreInput::MOUSE_BUTTON3, lParam,wParam);
+	break;
+	case WM_KEYDOWN:
+		if(core) {
+				wchar_t unicodeChar = 0;
+				MSG m;
+				m.hwnd = hWnd;
+				m.message = message;
+				m.wParam = wParam;
+				m.lParam = lParam;
+				m.time = 0;
+				if ( PeekMessage(&m, hWnd, 0, WM_USER, PM_NOREMOVE) && (m.message == WM_CHAR) ) {
+					GetMessage(&m, hWnd, 0, WM_USER);
+			    		unicodeChar = (wchar_t)m.wParam;
+				}
+
+			core->handleKeyDown(lParam,wParam, unicodeChar);
+		}
+	break;
+	case WM_KEYUP:
+		if(core)
+			core->handleKeyUp(lParam,wParam);
+	break;
+	case WM_CLOSE:
+		if(core)
+			core->Shutdown();
+		useDefault = true;
+	break;
+	case WM_DESTROY:
+		PostQuitMessage(0);
+		break;
+      case WM_COMMAND:
+            switch(LOWORD(wParam))
+            {
+                case ID_FILE_EXIT:
+					if(core)
+						core->Shutdown();
+                break;
+				 case ID_FILE_OPEN:
+					 {
+					TCHAR szFile[2048];
+					 OPENFILENAME ofn;
+					 ZeroMemory(&ofn, sizeof(ofn));
+					ofn.lStructSize = sizeof(ofn);
+					ofn.hwndOwner = hWnd;
+					ofn.lpstrFile = szFile;
+					ofn.lpstrFile[0] = '\0';
+ofn.nMaxFile = sizeof(szFile);
+ofn.lpstrFilter = L"Polycode Application (*.polyapp)\0*.POLYAPP\0";
+ofn.nFilterIndex = 0;
+ofn.lpstrFileTitle = NULL;
+ofn.nMaxFileTitle = 0;
+ofn.lpstrInitialDir = NULL;
+ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST;
+
+
+						 if (GetOpenFileName(&ofn)==TRUE) {
+
+							 TCHAR tpath[2049];
+							 GetModuleFileName(NULL, (LPWSTR)tpath, 2048);
+							 STARTUPINFO si;
+							 PROCESS_INFORMATION pi;
+							 ZeroMemory(&si, sizeof(si));
+							 
+							 String fullLine = String(tpath);
+
+							 CreateProcess(fullLine.getWDataWithEncoding(String::ENCODING_UTF8), szFile, NULL, NULL, false, 0, 0, NULL, &si, &pi);
+						 }
+					 }
+                break;
+                case ID_SHOW_CONSOLE:
+					ShowWindow(consoleHwnd, SW_SHOW);
+					UpdateWindow(consoleHwnd);
+                break;
+            }
+        break;
+	default:
+		useDefault = true;
+		break;
+	}
+	
+	if (useDefault)
+		return DefWindowProc(hWnd, message, wParam, lParam);
+	else
+		return 0;
+}
+
+
+LRESULT CALLBACK ConsoleWindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
+{
+	int wmId, wmEvent;
+	PAINTSTRUCT ps;
+	HDC hdc;		
+	int nWidth, nHeight;
+
+	switch (message)
+	{
+	case WM_CLOSE:
+		ShowWindow(consoleHwnd, SW_HIDE);
+		UpdateWindow(consoleHwnd);
+	break;
+	default:
+		return DefWindowProc(hWnd, message, wParam, lParam);
+	}
+	return 0;
+}
+
+void AppendTextToEditCtrl(HWND hWndEdit, LPCTSTR pszText)
+{
+   int nLength = Edit_GetTextLength(hWndEdit); 
+   Edit_SetSel(hWndEdit, nLength, nLength);
+   Edit_ReplaceSel(hWndEdit, pszText);
+}
+
+
+void PolycodePlayerView::handleEvent(Event *event){
+	PolycodeDebugEvent *debugEvent = (PolycodeDebugEvent*) event;
+	switch(event->getEventCode()) {
+	case PolycodeDebugEvent::EVENT_ERROR:
+		{
+		String lineString = String("Error on line ");
+		lineString = lineString + String::NumberToString(debugEvent->lineNumber);
+		lineString = lineString + " - ";
+		AppendTextToEditCtrl(consoleTextArea, lineString.getWDataWithEncoding(String::ENCODING_UTF8));
+		AppendTextToEditCtrl(consoleTextArea, debugEvent->errorString.getWDataWithEncoding(String::ENCODING_UTF8));
+		ShowWindow(consoleHwnd, SW_SHOW);
+		UpdateWindow(consoleHwnd);
+		}
+	break;
+	case PolycodeDebugEvent::EVENT_PRINT:
+		AppendTextToEditCtrl(consoleTextArea, debugEvent->errorString.getWDataWithEncoding(String::ENCODING_UTF8));
+		ShowWindow(consoleHwnd, SW_SHOW);
+		UpdateWindow(consoleHwnd);
+	break;
+
+	}
+}
+
+
+PolycodePlayerView::PolycodePlayerView(bool standaloneMode, HINSTANCE hInstance, int nCmdShow, LPCTSTR windowTitle) : PolycodeViewBase(), EventHandler() {
+
+WNDCLASSEX wcex;
+
+	wcex.cbSize = sizeof(WNDCLASSEX);
+	wcex.style			= CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
+	wcex.lpfnWndProc	= WndProc;
+	wcex.cbClsExtra		= 0;
+	wcex.cbWndExtra		= 0;
+	wcex.hInstance		= hInstance;
+	wcex.hIcon			= LoadIcon(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_MYICON));
+	//wcex.hIconSm  = (HICON)LoadImage(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_MYICON), IMAGE_ICON, 16, 16, 0);
+	wcex.hCursor		= LoadCursor(NULL, IDC_ARROW);
+	wcex.hbrBackground	= NULL;
+	if(standaloneMode) {
+		wcex.lpszMenuName	=  NULL;
+	} else {
+		wcex.lpszMenuName	=  MAKEINTRESOURCE(IDR_MYMENU);;
+	}
+	wcex.lpszClassName	= L"POLYCODEAPPLICATION";
+	wcex.hIconSm		= LoadIcon(hInstance, IDI_APPLICATION);
+
+	RegisterClassEx(&wcex);
+
+  hwnd = CreateWindowEx(WS_EX_APPWINDOW, L"POLYCODEAPPLICATION", windowTitle, WS_OVERLAPPED|WS_SYSMENU,
+      0, 0, 640, 480, NULL, NULL, hInstance, NULL);
+
+  windowData = (void*)&hwnd;
+
+   ShowWindow(hwnd, nCmdShow);
+   UpdateWindow(hwnd);
+
+	WNDCLASSEX console_wcex;
+
+	console_wcex.cbSize = sizeof(WNDCLASSEX);
+	console_wcex.style			= CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
+	console_wcex.lpfnWndProc	= ConsoleWindowProc;
+	console_wcex.cbClsExtra		= 0;
+	console_wcex.cbWndExtra		= 0;
+	console_wcex.hInstance		= hInstance;
+	console_wcex.hIcon			= LoadIcon(hInstance, IDI_APPLICATION);
+	console_wcex.hCursor		= LoadCursor(NULL, IDC_ARROW);
+	console_wcex.hbrBackground	= NULL;
+	console_wcex.lpszMenuName	= NULL;
+	console_wcex.lpszClassName	= L"CONSOLEWINDOW";
+	console_wcex.hIconSm		= LoadIcon(hInstance, IDI_APPLICATION);
+
+	RegisterClassEx(&console_wcex);
+
+	consoleHwnd = CreateWindowEx(WS_EX_TOOLWINDOW, L"CONSOLEWINDOW", L"Debug console.", WS_OVERLAPPED|WS_SYSMENU,
+		640, 100, 500, 300, hwnd, NULL, hInstance, NULL);
+
+	//ShowWindow(consoleHwnd, SW_SHOW);
+	UpdateWindow(consoleHwnd);
+
+	consoleTextArea = CreateWindowEx(WS_EX_CLIENTEDGE, L"EDIT", L"",  WS_CHILD | WS_VISIBLE|ES_MULTILINE|ES_AUTOVSCROLL|ES_READONLY,
+		0, 0, 500, 275, consoleHwnd, NULL, hInstance, NULL);
+
+
+	ShowWindow(consoleTextArea, SW_SHOW);
+	UpdateWindow(consoleTextArea);
+
+	HFONT defaultFont = (HFONT)GetStockObject(DEFAULT_GUI_FONT);
+	SendMessage (consoleTextArea, WM_SETFONT, WPARAM (defaultFont), TRUE);
+
+}
+
+PolycodePlayerView::~PolycodePlayerView() {
+
+}

+ 31 - 1
Standalone/CMakeLists.txt

@@ -14,12 +14,40 @@ INSTALL(DIRECTORY ${PolycodeStandalone_SOURCE_DIR}/../Modules/Bindings/3DPhysics
 INSTALL(DIRECTORY ${PolycodeStandalone_SOURCE_DIR}/../Examples/Lua DESTINATION Examples)
 
 IF(MSVC OR MINGW)
+
+  INSTALL(FILES ${POLYCODE_RELEASE_DIR}/Framework/Core/Dependencies/bin/OpenAL32.dll DESTINATION Player)
+  INSTALL(FILES ${POLYCODE_RELEASE_DIR}/Framework/Core/Dependencies/bin/OpenAL32.dll DESTINATION Publish/Win)
+
+	INSTALL(FILES ${POLYCODE_RELEASE_DIR}/Framework/Player/PolycodePlayer.exe DESTINATION Player)
+	INSTALL(FILES ${POLYCODE_RELEASE_DIR}/Framework/Player/default.pak DESTINATION Player)
+	INSTALL(FILES ${POLYCODE_RELEASE_DIR}/Framework/Player/hdr.pak DESTINATION Player)
+	INSTALL(FILES ${POLYCODE_RELEASE_DIR}/Framework/Player/api.pak DESTINATION Player)
+	INSTALL(FILES ${POLYCODE_RELEASE_DIR}/Framework/Player/StandalonePlayer.exe DESTINATION Publish/Win)
+	INSTALL(FILES ${POLYCODE_RELEASE_DIR}/Framework/Player/default.pak DESTINATION Publish/Win)
+	INSTALL(FILES ${POLYCODE_RELEASE_DIR}/Framework/Player/hdr.pak DESTINATION Publish/Win)
+	INSTALL(FILES ${POLYCODE_RELEASE_DIR}/Framework/Player/api.pak DESTINATION Publish/Win)
+	INSTALL(FILES ${POLYCODE_RELEASE_DIR}/Framework/Player/main.polyapp DESTINATION Publish/Win)
+	INSTALL(FILES ${POLYCODE_RELEASE_DIR}/Framework/Bindings/Lua/Modules/2DPhysics/lib/Physics2D.dll DESTINATION Modules/Physics2D/Lib/win)
+	INSTALL(FILES ${POLYCODE_RELEASE_DIR}/Framework/Bindings/Lua/Modules/3DPhysics/lib/Physics3D.dll DESTINATION Modules/Physics3D/Lib/win)
+
+INSTALL(PROGRAMS ${POLYCODE_RELEASE_DIR}/Framework/Tools/polybuild.exe DESTINATION Bin)
+INSTALL(PROGRAMS ${POLYCODE_RELEASE_DIR}/Framework/Tools/polyimport.exe DESTINATION Bin)
+INSTALL(DIRECTORY ${PolycodeStandalone_SOURCE_DIR}/../Assets/Templates/Lua DESTINATION Template)
+
+
 ELSEIF(APPLE)
+
 	INSTALL(DIRECTORY ${POLYCODE_RELEASE_DIR}/Framework/Player/PolycodePlayer.app DESTINATION Player USE_SOURCE_PERMISSIONS)
 	INSTALL(DIRECTORY ${POLYCODE_RELEASE_DIR}/Framework/Player/StandalonePlayer.app DESTINATION Publish/Mac USE_SOURCE_PERMISSIONS)
 	INSTALL(FILES ${POLYCODE_RELEASE_DIR}/Framework/Bindings/Lua/Modules/2DPhysics/lib/Physics2D.dylib DESTINATION Modules/Physics2D/Lib/osx)
 	INSTALL(FILES ${POLYCODE_RELEASE_DIR}/Framework/Bindings/Lua/Modules/3DPhysics/lib/Physics3D.dylib DESTINATION Modules/Physics3D/Lib/osx)
+
+INSTALL(PROGRAMS ${POLYCODE_RELEASE_DIR}/Framework/Tools/polybuild DESTINATION Bin)
+INSTALL(PROGRAMS ${POLYCODE_RELEASE_DIR}/Framework/Tools/polyimport DESTINATION Bin)
+INSTALL(DIRECTORY ${PolycodeStandalone_SOURCE_DIR}/../Assets/Templates/Lua DESTINATION Template)
+
 ELSE(MSVC OR MINGW)
+
 	INSTALL(PROGRAMS ${POLYCODE_RELEASE_DIR}/Framework/Player/PolycodePlayer DESTINATION Player)
 	INSTALL(FILES ${POLYCODE_RELEASE_DIR}/Framework/Player/default.pak DESTINATION Player)
 	INSTALL(FILES ${POLYCODE_RELEASE_DIR}/Framework/Player/hdr.pak DESTINATION Player)
@@ -31,10 +59,12 @@ ELSE(MSVC OR MINGW)
 	INSTALL(FILES ${POLYCODE_RELEASE_DIR}/Framework/Player/main.polyapp DESTINATION Publish/Linux)
 	INSTALL(FILES ${POLYCODE_RELEASE_DIR}/Framework/Bindings/Lua/Modules/2DPhysics/lib/Physics2D.so DESTINATION Modules/Physics2D/Lib/linux)
 	INSTALL(FILES ${POLYCODE_RELEASE_DIR}/Framework/Bindings/Lua/Modules/3DPhysics/lib/Physics3D.so DESTINATION Modules/Physics3D/Lib/linux)
-ENDIF(MSVC OR MINGW)
 
 INSTALL(PROGRAMS ${POLYCODE_RELEASE_DIR}/Framework/Tools/polybuild DESTINATION Bin)
 INSTALL(PROGRAMS ${POLYCODE_RELEASE_DIR}/Framework/Tools/polyimport DESTINATION Bin)
 INSTALL(DIRECTORY ${PolycodeStandalone_SOURCE_DIR}/../Assets/Templates/Lua DESTINATION Template)
 
 
+ENDIF(MSVC OR MINGW)
+
+