项目环境搭建

文章介绍了PhotonServer4的日志输出配置,包括添加log4net库文件,配置log4net.config文件以实现滚动文件和控制台日志记录。同时,详细阐述了基于.NetFramework的服务器基础开发步骤,如新建项目,添加依赖库,配置服务器启动时的日志路径。此外,还提及了PhotonServer4的实例设置,如UDP和TCP监听器配置,以及cocos2d-x在Windows上的开发环境搭建,包括CMake的使用和源码管理。
摘要由CSDN通过智能技术生成



.Net、.Net Core、.Net Standard、.Net Framework、Mono的关系


> PhotonServer4 添加日志输出

1. 添加对应的库文件,2个dll
在这里插入图片描述

2. 从Mmo Server中复制log4net.config配置文件,修改属性为始终复制

<?xml version="1.0" encoding="utf-8" ?>
<log4net debug="false" update="Overwrite">

  <appender name="RollingFileAppender" type="log4net.Appender.RollingFileAppender">
    <file type="log4net.Util.PatternString" value="%property{Photon:ApplicationLogPath}\\TutorialServer.log" />
    <appendToFile value="true" />
    <maximumFileSize value="5000KB" />
    <maxSizeRollBackups value="2" />
    <layout type="log4net.Layout.PatternLayout">
      <conversionPattern value="%d [%t] %-5p %c - %m%n" />
    </layout>
  </appender>

  <appender name="ConsoleAppender" type="log4net.Appender.ConsoleAppender">
    <layout type="log4net.Layout.PatternLayout">
      <param name="ConversionPattern" value="%d [%t] %-5p %c - %m%n" />
    </layout>
    <filter type="log4net.Filter.LevelRangeFilter">
      <levelMin value="DEBUG" />
      <levelMax value="FATAL" />
    </filter>
  </appender>

  <!-- logger -->
  <root>
    <level value="INFO" />
    <!--<appender-ref ref="ConsoleAppender" />-->
    <appender-ref ref="RollingFileAppender" />
  </root>

  <logger name="OperationData">
    <level value="INFO" />
  </logger>

</log4net>

3. 服务器启动的时候配置

protected override void Setup()
{
    log4net.GlobalContext.Properties["Photon:ApplicationLogPath"] = Path.Combine(Path.Combine(Path.Combine(this.ApplicationRootPath, "bin_win64")), "log");
    FileInfo configFileInfo = new FileInfo(Path.Combine(this.BinaryPath, "log4net.config"));
    if (configFileInfo.Exists)
    {
        LogManager.SetLoggerFactory(Log4NetLoggerFactory.Instance);
        XmlConfigurator.ConfigureAndWatch(configFileInfo);
    }

    _log.Info("服务器已经启动");
}

> PhotonServer4基本Server开发

1. 新建.NetFramework类库项目
2. 添加相关的.dll库,3个库就可以开发Server了
在这里插入图片描述
3. 服务器入口继承自ApplicationBase,客户端继承自ClientPeer
4. 新建对应的Server目录Photon4\deploy\TutorialServer\bin
5. 配置PhotoServer控制台 PhotonServer.config

<!-- Instance settings -->
<TutorialInstance
	MaxMessageSize="512000"
	MaxQueuedDataPerPeer="512000"
	PerPeerMaxReliableDataInTransit="51200"
	PerPeerTransmitRateLimitKBSec="256"
	PerPeerTransmitRatePeriodMilliseconds="200"
	MinimumTimeout="5000"
	MaximumTimeout="30000"
	DisplayName="Tutorial Server"> <!-- 显示名字 -->
	
	<!-- 0.0.0.0 opens listeners on all available IPs. Machines with multiple IPs should define the correct one here. -->
	<!-- Port 5055 is Photon's default for UDP connections. -->
	<UDPListeners>
		<UDPListener
			IPAddress="0.0.0.0"
			Port="5055"
			OverrideApplication="TutorialServer"> <!-- Udp应用的App,可配置多个 -->
		</UDPListener>
	</UDPListeners>
   
	<!-- 0.0.0.0 opens listeners on all available IPs. Machines with multiple IPs should define the correct one here. -->
	<!-- Port 4530 is Photon's default for TCP connecttions. -->
	<!-- A Policy application is defined in case that policy requests are sent to this listener (known bug of some some flash clients) --> 
	<TCPListeners>
		<TCPListener
			IPAddress="0.0.0.0"
			Port="4530"
			PolicyFile="Policy\assets\socket-policy.xml"
			InactivityTimeout="10000"
			OverrideApplication="TutorialServer">  <!-- Tcp应用的App,可配置多个 -->
		</TCPListener>
	</TCPListeners>

	<!-- Policy request listener for Unity and Flash (port 843) and Silverlight (port 943)  -->
	<PolicyFileListeners>
	  <!-- multiple Listeners allowed for different ports -->
	  <PolicyFileListener
		IPAddress="0.0.0.0"
		Port="843"
		PolicyFile="Policy\assets\socket-policy.xml"
		InactivityTimeout="10000">
	  </PolicyFileListener>
	  <PolicyFileListener
		IPAddress="0.0.0.0"
		Port="943"
		PolicyFile="Policy\assets\socket-policy-silverlight.xml"
		InactivityTimeout="10000">
	  </PolicyFileListener>
	</PolicyFileListeners>

	<!-- WebSocket (and Flash-Fallback) compatible listener 
	<WebSocketListeners>  
		<WebSocketListener
			IPAddress="0.0.0.0"
			Port="9090"
			DisableNagle="true"
			InactivityTimeout="10000"
			OverrideApplication="MMoDemo">  <WebSocket看需求关闭>
		</WebSocketListener>
	</WebSocketListeners> -->

	<!-- Defines the Photon Runtime Assembly to use. -->
	<Runtime
		Assembly="PhotonHostRuntime, Culture=neutral"
		Type="PhotonHostRuntime.PhotonDomainManager"
		UnhandledExceptionPolicy="Ignore">
	</Runtime>
			

	<!-- Defines which applications are loaded on start and which of them is used by default. Make sure the default application is defined. -->
	<!-- Application-folders must be located in the same folder as the bin_win32 folders. The BaseDirectory must include a "bin" folder. -->
	<Applications Default="TutorialServer">  <!-- 默认链接的App -->
	
		<!-- MMO Demo Application -->  <!-- 配置应用的名字,目录,dll,命名空间 -->
		<Application
			Name="TutorialServer" 
			BaseDirectory="TutorialServer"
			Assembly="TutorialServer"
			Type="TutorialServer.TutorialApp"
			ForceAutoRestart="true"
			WatchFiles="dll;config"
			ExcludeFiles="log4net.config">
		</Application>

		<!-- CounterPublisher Application DEMO--> <!-- 可以参考CounterPublisher来配置 -->
		<Application
			Name="CounterPublisher"
			BaseDirectory="CounterPublisher"
			Assembly="CounterPublisher"
			Type="Photon.CounterPublisher.Application"
			ForceAutoRestart="true"
			WatchFiles="dll;config"
			ExcludeFiles="log4net.config">
		</Application>	

	</Applications>
</TutorialInstance>  <!-- 应用配置 -->



cocos2d-x默认只支持win32的版本,win64的我测试link不行

我搭建使用的环境
windows10+vs2019+py2.7+cmake3

在这里插入图片描述


  1. 从GitHub上clone源码https://github.com/cocos2d/cocos2d-x
    coco2d-x默认带了submodule,有协同子模块,最好是一起下载,搞个完整版
    下载完源码以后需要更新submodule
    git submodule update --init
    git submodule update
    或ToturtiesGit中选择
    在这里插入图片描述

如果submodule下载异常,可以手动下载,在.gitmodules文件中有列表
下载zip包放到对应的位置


  1. 全局Cmake,我为了方便就使用了全局Cmake
    在cocos2d-x目录下面创建一个目录build,存放cmake之后的文件
    我使用的GUI界面Cmake,我使用的系统包括Cmake都是最新的,默认是x64的
    使用GUI可以方便选择
    在这里插入图片描述
    在这里插入图片描述
    配置完之后,然后点生成,就可以打开全局生成的项目
    在这里插入图片描述

  1. 运行测试
    在这里插入图片描述
    可以看到cocos2d-x4.0的low帧率极低,异常稳定
    改进了很多,多少年之前使用了的引擎,最初的,国产的还是香

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值