Skip to content

Commit

Permalink
Merge pull request #30 from MSOpenTech/v3.10-win10
Browse files Browse the repository at this point in the history
V3.10 Add support for Windows 10 UWP and Windows 8.1 Universal Apps
  • Loading branch information
slackmoehrle committed Apr 15, 2016
2 parents cb164cf + ace9208 commit 4449554
Show file tree
Hide file tree
Showing 61 changed files with 4,572 additions and 6 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Expand Up @@ -33,7 +33,9 @@ obj/
_ReSharper*/
[Tt]est[Rr]esult*
ipch/
Generated Files/
*.opensdf
*.opendb

# Ignore files build by ndk and eclipse
#libs/
Expand Down Expand Up @@ -112,6 +114,9 @@ tests/*/publish/
# Android
project.properties

# Ignore winrt cocos2d folder
/cpp/cocos2d/

# Ignore prebuilt libraries folder
/external/xxhash/
/external/curl/
Expand Down
39 changes: 37 additions & 2 deletions README.md
Expand Up @@ -17,17 +17,52 @@ libs/libcocos2d iOS.a
```
For Android you should have everything if you have the Cocos app installed. If you do not, you can drop the pre-built libraries into __libs/__ and edit your projects config to reflect this.

For Windows 10 UWP and Windows 8.1 Universal App projects (WinRT Platforms) it is easier to work with the cocos2d-x source. Do the following:
```
$ cd programmers-guide-samples/cpp
$ git clone https://github.com/cocos2d/cocos2d-x.git cocos2d
$ cd cocos2d
$ git checkout v3.10
$ git submodule update --init
$ download-deps.py
```
This will setup the cocos2d-x code needed by the Windows 10 and 8.1 projects.


## How to compile the samples
iOS:
```
$ git clone https://github.com/chukong/programmers-guide-samples.git
$ cd programmers-guide-samples
$ cd programmers-guide-samples/cpp
$ open proj.ios_mac/Programmers\ Guide.xcodeproj/
```
Android:
```
$ git clone https://github.com/chukong/programmers-guide-samples.git
$ cd programmers-guide-samples
$ cd programmers-guide-samples/cpp
$ cd proj.android
$ cocos run -p android
```
Windows 10 UWP (WinRT Platform):
```
$ git clone https://github.com/chukong/programmers-guide-samples.git
$ cd programmers-guide-samples/cpp
$ cd proj.win10
1. Open test.sln with VS2015 update 1
2. Select the Debug/x86 configuration
3. Right click on the test project and select Set as StartUp Project from the menu
4. Select Start Debugging from the Debug menu
```
Windows 8.1 Universal App (WinRT Platform):
```
$ git clone https://github.com/chukong/programmers-guide-samples.git
$ cd programmers-guide-samples/cpp
$ cd proj.win8.1-universal
1. Open test.sln with VS2015 Update 1 or Visual Studio 2013 Update 4 or 5
2. Select the Debug/x86 configuration
3. Right click on the test project and select Set as StartUp Project from the menu
4. Select Start Debugging from the Debug menu
```
13 changes: 13 additions & 0 deletions cpp/proj.win10/App/App.xaml
@@ -0,0 +1,13 @@
<Application
x:Class="CocosAppWinRT.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:CocosAppWinRT"
xmlns:localData="using:Shared">

<Application.Resources>

<x:String x:Key="AppName">HelloCpp</x:String>

</Application.Resources>
</Application>
65 changes: 65 additions & 0 deletions cpp/proj.win10/App/App.xaml.cpp
@@ -0,0 +1,65 @@
#include "App.xaml.h"
#include "OpenGLESPage.xaml.h"

using namespace Platform;
using namespace Windows::ApplicationModel;
using namespace Windows::ApplicationModel::Activation;
using namespace Windows::Foundation;
using namespace Windows::Foundation::Collections;
using namespace Windows::UI::Xaml::Media::Animation;
using namespace Windows::UI::Xaml;
using namespace Windows::UI::Xaml::Controls;
using namespace Windows::UI::Xaml::Controls::Primitives;
using namespace Windows::UI::Xaml::Data;
using namespace Windows::UI::Xaml::Input;
using namespace Windows::UI::Xaml::Interop;
using namespace Windows::UI::Xaml::Media;
using namespace Windows::UI::Xaml::Navigation;
using namespace cocos2d;
using namespace CocosAppWinRT;

App::App()
{
InitializeComponent();
Suspending += ref new SuspendingEventHandler(this, &App::OnSuspending);
Resuming += ref new EventHandler<Object^>(this, &App::OnResuming);
}

void App::OnLaunched(Windows::ApplicationModel::Activation::LaunchActivatedEventArgs^ e)
{
if (mPage == nullptr)
{
mPage = ref new OpenGLESPage(&mOpenGLES);
}

// Place the page in the current window and ensure that it is active.
Windows::UI::Xaml::Window::Current->Content = mPage;
Windows::UI::Xaml::Window::Current->Activate();
}

/// <summary>
/// Invoked when application execution is being suspended. Application state is saved
/// without knowing whether the application will be terminated or resumed with the contents
/// of memory still intact.
/// </summary>
void App::OnSuspending(Object^ sender, SuspendingEventArgs^ e)
{
(void)sender; // Unused parameter
(void)e; // Unused parameter

mPage->SetVisibility(false);
}

/// <summary>
/// Invoked when application execution is being resumed.
/// </summary>
/// <param name="sender">The source of the resume request.</param>
/// <param name="args">Details about the resume request.</param>
void App::OnResuming(Object ^sender, Object ^args)
{
(void)sender; // Unused parameter
(void)args; // Unused parameter

mPage->SetVisibility(true);
}

22 changes: 22 additions & 0 deletions cpp/proj.win10/App/App.xaml.h
@@ -0,0 +1,22 @@
#pragma once

#include "app.g.h"
#include "OpenGLES.h"
#include "openglespage.xaml.h"

namespace CocosAppWinRT
{
ref class App sealed
{
public:
App();
virtual void OnLaunched(Windows::ApplicationModel::Activation::LaunchActivatedEventArgs^ e) override;

private:
void OnSuspending(Platform::Object^ sender, Windows::ApplicationModel::SuspendingEventArgs^ e);
void OnResuming(Platform::Object ^sender, Platform::Object ^args);

OpenGLESPage^ mPage;
OpenGLES mOpenGLES;
};
}
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added cpp/proj.win10/App/Assets/StoreLogo.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
156 changes: 156 additions & 0 deletions cpp/proj.win10/App/Cocos2dEngine/Cocos2dRenderer.cpp
@@ -0,0 +1,156 @@
/*
* cocos2d-x http://www.cocos2d-x.org
*
* Copyright (c) 2010-2014 - cocos2d-x community
*
* Portions Copyright (c) Microsoft Open Technologies, Inc.
* All Rights Reserved
*
* 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.
*/

#include "Cocos2dRenderer.h"
#include "AppDelegate.h"
#include "CCGLViewImpl-winrt.h"
#include "CCApplication.h"
#include "cocos2d.h"
#include "renderer/CCTextureCache.h"

// These are used by the shader compilation methods.
#include <vector>
#include <iostream>
#include <fstream>

using namespace Platform;
using namespace Windows::UI::Core;
using namespace Windows::UI::Xaml::Controls;
using namespace Windows::Graphics::Display;
using namespace cocos2d;

Cocos2dRenderer::Cocos2dRenderer(int width, int height, float dpi, DisplayOrientations orientation, CoreDispatcher^ dispatcher, Panel^ panel)
: m_app(nullptr)
, m_width(width)
, m_height(height)
, m_dpi(dpi)
, m_dispatcher(dispatcher)
, m_panel(panel)
, m_orientation(orientation)
{
m_app = new AppDelegate();
}

Cocos2dRenderer::~Cocos2dRenderer()
{
delete m_app;
}

void Cocos2dRenderer::Resume()
{
auto director = cocos2d::Director::getInstance();
auto glview = director->getOpenGLView();

if (!glview)
{
GLViewImpl* glview = GLViewImpl::create("Test Cpp");
glview->setDispatcher(m_dispatcher.Get());
glview->setPanel(m_panel.Get());
glview->Create(static_cast<float>(m_width), static_cast<float>(m_height), m_dpi, m_orientation);
director->setOpenGLView(glview);
CCApplication::getInstance()->run();
}
else
{
Application::getInstance()->applicationWillEnterForeground();
cocos2d::EventCustom foregroundEvent(EVENT_COME_TO_FOREGROUND);
cocos2d::Director::getInstance()->getEventDispatcher()->dispatchEvent(&foregroundEvent);
}
}

void Cocos2dRenderer::Pause()
{
if (Director::getInstance()->getOpenGLView()) {
Application::getInstance()->applicationDidEnterBackground();
cocos2d::EventCustom backgroundEvent(EVENT_COME_TO_BACKGROUND);
cocos2d::Director::getInstance()->getEventDispatcher()->dispatchEvent(&backgroundEvent);
}
}

bool Cocos2dRenderer::AppShouldExit()
{
return GLViewImpl::sharedOpenGLView()->AppShouldExit();
}

void Cocos2dRenderer::DeviceLost()
{
Pause();

auto director = cocos2d::Director::getInstance();
if (director->getOpenGLView()) {
cocos2d::GL::invalidateStateCache();
cocos2d::GLProgramCache::getInstance()->reloadDefaultGLPrograms();
cocos2d::DrawPrimitives::init();
cocos2d::VolatileTextureMgr::reloadAllTextures();

cocos2d::EventCustom recreatedEvent(EVENT_RENDERER_RECREATED);
director->getEventDispatcher()->dispatchEvent(&recreatedEvent);
director->setGLDefaultValues();

Application::getInstance()->applicationWillEnterForeground();
cocos2d::EventCustom foregroundEvent(EVENT_COME_TO_FOREGROUND);
cocos2d::Director::getInstance()->getEventDispatcher()->dispatchEvent(&foregroundEvent);
}
}



void Cocos2dRenderer::Draw(GLsizei width, GLsizei height, float dpi, DisplayOrientations orientation)
{
auto glView = GLViewImpl::sharedOpenGLView();

if (orientation != m_orientation)
{
m_orientation = orientation;
glView->UpdateOrientation(orientation);
}

if (width != m_width || height != m_height)
{
m_width = width;
m_height = height;
glView->UpdateForWindowSizeChange(static_cast<float>(width), static_cast<float>(height));
}

if (dpi != m_dpi)
{
m_dpi = dpi;
glView->SetDPI(m_dpi);
}

glView->ProcessEvents();
glView->Render();
}

void Cocos2dRenderer::QueuePointerEvent(cocos2d::PointerEventType type, Windows::UI::Core::PointerEventArgs^ args)
{
GLViewImpl::sharedOpenGLView()->QueuePointerEvent(type, args);
}

void Cocos2dRenderer::QueueBackButtonEvent()
{
GLViewImpl::sharedOpenGLView()->QueueBackKeyPress();
}

void Cocos2dRenderer::QueueKeyboardEvent(WinRTKeyboardEventType type, Windows::UI::Core::KeyEventArgs^ args)
{
GLViewImpl::sharedOpenGLView()->QueueWinRTKeyboardEvent(type, args);
}



54 changes: 54 additions & 0 deletions cpp/proj.win10/App/Cocos2dEngine/Cocos2dRenderer.h
@@ -0,0 +1,54 @@
/*
* cocos2d-x http://www.cocos2d-x.org
*
* Copyright (c) 2010-2014 - cocos2d-x community
*
* Portions Copyright (c) Microsoft Open Technologies, Inc.
* All Rights Reserved
*
* 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.
*/
#pragma once

#include <agile.h>

#include "cocos2d.h"


class AppDelegate;

class Cocos2dRenderer
{
public:
Cocos2dRenderer(int width, int height, float dpi,
Windows::Graphics::Display::DisplayOrientations orientation,
Windows::UI::Core::CoreDispatcher^ dispatcher, Windows::UI::Xaml::Controls::Panel^ panel);
~Cocos2dRenderer();
void Draw(GLsizei width, GLsizei height, float dpi, Windows::Graphics::Display::DisplayOrientations orientation);
void QueuePointerEvent(cocos2d::PointerEventType type, Windows::UI::Core::PointerEventArgs^ args);
void QueueKeyboardEvent(cocos2d::WinRTKeyboardEventType type, Windows::UI::Core::KeyEventArgs^ args);
void QueueBackButtonEvent();
void Pause();
void Resume();
void DeviceLost();
bool AppShouldExit();

private:

int m_width;
int m_height;
float m_dpi;

// The AppDelegate for the Cocos2D app
AppDelegate* m_app;
Platform::Agile<Windows::UI::Core::CoreDispatcher> m_dispatcher;
Platform::Agile<Windows::UI::Xaml::Controls::Panel> m_panel;
Windows::Graphics::Display::DisplayOrientations m_orientation;
};

0 comments on commit 4449554

Please sign in to comment.