项目环境搭建
2dx win10环境搭建
.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
- 从GitHub上clone源码https://github.com/cocos2d/cocos2d-x
coco2d-x默认带了submodule,有协同子模块,最好是一起下载,搞个完整版
下载完源码以后需要更新submodule
git submodule update --init
git submodule update
或ToturtiesGit中选择
如果submodule下载异常,可以手动下载,在
.gitmodules
文件中有列表
下载zip包放到对应的位置
- 全局Cmake,我为了方便就使用了全局Cmake
在cocos2d-x目录下面创建一个目录build
,存放cmake之后的文件
我使用的GUI界面Cmake,我使用的系统包括Cmake都是最新的,默认是x64的
使用GUI可以方便选择
配置完之后,然后点生成,就可以打开全局生成的项目
- 运行测试
cocos new test1 -p com.test.game -l cpp -d .
可以看到cocos2d-x4.0的low帧率极低,异常稳定
改进了很多,多少年之前使用了的引擎,最初的,国产的还是香
这里是一个专注于游戏开发的社区,我们致力于为广大游戏爱好者提供一个良好的学习和交流平台。我们的专区包含了各大流行引擎的技术博文,涵盖了从入门到进阶的各个阶段,无论你是初学者还是资深开发者,都能在这里找到适合自己的内容。除此之外,我们还会不定期举办游戏开发相关的活动,让大家更好地交流互动。加入我们,一起探索游戏开发的奥秘吧!
更多推荐
所有评论(0)