diff -i -E -b -w -B -u -r -N -d RetroBlaster/GROUP/Bld.inf RetroBlasterBt/GROUP/Bld.inf --- RetroBlaster/GROUP/Bld.inf 2003-04-02 22:42:14.000000000 +0200 +++ RetroBlasterBt/GROUP/Bld.inf 2003-11-19 22:10:47.000000000 +0100 @@ -6,4 +6,5 @@ PRJ_MMPFILES +..\..\NetworkingDll\NetworkingDll.mmp RetroBlaster.mmp diff -i -E -b -w -B -u -r -N -d RetroBlaster/GROUP/RETROBLASTER.pkg RetroBlasterBt/GROUP/RETROBLASTER.pkg --- RetroBlaster/GROUP/RETROBLASTER.pkg 2003-07-22 19:02:34.000000000 +0200 +++ RetroBlasterBt/GROUP/RETROBLASTER.pkg 2003-11-19 22:38:00.000000000 +0100 @@ -7,6 +7,9 @@ ; ; The following paths assume that the SDK is installed in the default ; location, and will need to be modified if this is not the case -"C:\Symbian\6.1\Series60\Epoc32\Release\ARMI\UREL\RETROBLASTER.APP"-"!:\system\apps\RETROBLASTER\RETROBLASTER.app" -"C:\Symbian\6.1\Series60\Epoc32\Release\ARMI\UREL\RETROBLASTER.RSC"-"!:\system\apps\RETROBLASTER\RETROBLASTER.rsc" -"C:\Symbian\6.1\Series60\Epoc32\Release\ARMI\UREL\RETROBLASTER.MBM"-"!:\system\apps\RETROBLASTER\RETROBLASTER.MBM" +"\Symbian\6.1\Series60\Epoc32\Release\ARMI\UREL\RETROBLASTER.APP"-"!:\system\apps\RETROBLASTER\RETROBLASTER.app" +"\Symbian\6.1\Series60\Epoc32\Release\ARMI\UREL\RETROBLASTER.RSC"-"!:\system\apps\RETROBLASTER\RETROBLASTER.rsc" +"\Symbian\6.1\Series60\Epoc32\Release\ARMI\UREL\RETROBLASTER.MBM"-"!:\system\apps\RETROBLASTER\RETROBLASTER.MBM" + +"\Symbian\6.1\Series60\Epoc32\Release\ARMI\UREL\Essentials.DLL"-"!:\system\apps\RETROBLASTER\Essentials.DLL" +"\Symbian\6.1\Series60\Epoc32\Release\ARMI\UREL\Networking.DLL"-"!:\system\apps\RETROBLASTER\Networking.DLL" diff -i -E -b -w -B -u -r -N -d RetroBlaster/GROUP/RetroBlaster.mmp RetroBlasterBt/GROUP/RetroBlaster.mmp --- RetroBlaster/GROUP/RetroBlaster.mmp 2003-06-02 16:57:06.000000000 +0200 +++ RetroBlasterBt/GROUP/RetroBlaster.mmp 2003-11-20 10:52:49.000000000 +0100 @@ -35,6 +35,10 @@ SOURCE ShipAnim.cpp SOURCE Tilemap.cpp SOURCE Tileset.cpp +SOURCE GameProtocol.cpp +SOURCE LocalShip.cpp +SOURCE RemoteShip.cpp +SOURCE ShipBase.cpp SOURCEPATH . RESOURCE RetroBlaster.rss @@ -50,8 +54,13 @@ END USERINCLUDE ..\inc +SYSTEMINCLUDE ..\..\NetworkingDll\src +SYSTEMINCLUDE ..\..\EssentialsDll\src SYSTEMINCLUDE \epoc32\include +LIBRARY Networking.lib +LIBRARY Essentials.lib + LIBRARY euser.lib LIBRARY apparc.lib LIBRARY cone.lib @@ -64,4 +73,3 @@ AIF RetroBlaster.aif ..\Aif RetroBlasterAif.rss \ c12 RetroBlasterIcon.bmp RetroBlasterIconMask.bmp RetroBlasterIcon42x22.bmp RetroBlasterIcon42x22Mask.bmp - diff -i -E -b -w -B -u -r -N -d RetroBlaster/GROUP/RetroBlaster.rss RetroBlasterBt/GROUP/RetroBlaster.rss --- RetroBlaster/GROUP/RetroBlaster.rss 2003-05-26 15:46:52.000000000 +0200 +++ RetroBlasterBt/GROUP/RetroBlaster.rss 2003-11-19 22:01:00.000000000 +0100 @@ -63,7 +63,8 @@ { items = { - MENU_ITEM {command = ERetroGameStart; txt = "Start Game";}, + MENU_ITEM {command = ERetroGameServer; txt = "Start Server";}, + MENU_ITEM {command = ERetroGameClient; txt = "Start Client";}, MENU_ITEM {command = ERetroGameStop; txt = "Stop Game";}, MENU_ITEM {command = EAknSoftkeyExit; txt = "Exit";} }; diff -i -E -b -w -B -u -r -N -d RetroBlaster/INC/GameEventListener.h RetroBlasterBt/INC/GameEventListener.h --- RetroBlaster/INC/GameEventListener.h 1970-01-01 01:00:00.000000000 +0100 +++ RetroBlasterBt/INC/GameEventListener.h 2003-11-20 02:01:51.000000000 +0100 @@ -0,0 +1,21 @@ +// ------------ +// GameEventListener.h +// ------------ +// +// Copyright (c) 2003 Nokia Phones Ltd All rights reserved. +// + +#ifndef __MGameEventListener_H__ +#define __MGameEventListener_H__ + +#include + + + +class MGameEventListener +{ +public: + virtual void OnControlTick() = 0; +}; + +#endif diff -i -E -b -w -B -u -r -N -d RetroBlaster/INC/GameProtocol.h RetroBlasterBt/INC/GameProtocol.h --- RetroBlaster/INC/GameProtocol.h 1970-01-01 01:00:00.000000000 +0100 +++ RetroBlasterBt/INC/GameProtocol.h 2003-11-20 02:30:23.000000000 +0100 @@ -0,0 +1,55 @@ +// ------------ +// GameProtocol.h +// ------------ +// +// Copyright (c) 2003 Nokia Phones Ltd All rights reserved. +// + +#ifndef __CGameProtocol_H__ +#define __CGameProtocol_H__ + +#include + +#include + +#include "GameEventListener.h" + +class CRemoteShip; +class CRetroEngine; +class MNetworkSocket; + + + +class CGameProtocol : public CBase, public MGameEventListener, public CPacketSender::MPSListener +{ +public: + static CGameProtocol * NewL( CRetroEngine & aEngine ); + static CGameProtocol * NewLC( CRetroEngine & aEngine ); + ~CGameProtocol(); + +public: + void AddNewConnectionL( MNetworkSocket & aNewConnection ); + +protected: + /* From MGameEventListener */ + void OnControlTick(); + +protected: + /* From MPSListener */ + void OnSendComplete(); + void OnSendFailed( TInt aReasonCode ); + +protected: + CGameProtocol( CRetroEngine & aEngine ); + void ConstructL(); + +private: + CPacketSender* iSender; + TBuf8< 1024 > iSendBuffer; + RPointerArray< CRemoteShip > iRemoteShips; + +private: + CRetroEngine & iEngine; +}; + +#endif diff -i -E -b -w -B -u -r -N -d RetroBlaster/INC/LocalShip.h RetroBlasterBt/INC/LocalShip.h --- RetroBlaster/INC/LocalShip.h 1970-01-01 01:00:00.000000000 +0100 +++ RetroBlasterBt/INC/LocalShip.h 2003-11-20 03:09:23.000000000 +0100 @@ -0,0 +1,38 @@ +//////////////////////////////////////////////////////////////////////// +// +// LocalShip.h +// +// Copyright (c) 2003 Nokia Mobile Phones Ltd. All rights reserved. +// +//////////////////////////////////////////////////////////////////////// + +#ifndef __LocalShip_H__ +#define __LocalShip_H__ + +#include + +#include "ShipBase.h" + +class TKeyHandler; + + + +class CLocalShip : public CShipBase +{ +public: + static CLocalShip* NewL( TKeyHandler& aKeyHandler, CImageFactory& aImageFactory ); + static CLocalShip* NewLC( TKeyHandler& aKeyHandler, CImageFactory& aImageFactory ); + ~CLocalShip(); + +public: + void Simulate(); + +protected: + CLocalShip( TKeyHandler& aKeyHandler, CImageFactory& aImageFactory ); + void ConstructL(); + +private: + TKeyHandler& iKeyHandler; +}; + +#endif diff -i -E -b -w -B -u -r -N -d RetroBlaster/INC/RemoteShip.h RetroBlasterBt/INC/RemoteShip.h --- RetroBlaster/INC/RemoteShip.h 1970-01-01 01:00:00.000000000 +0100 +++ RetroBlasterBt/INC/RemoteShip.h 2003-11-20 02:13:29.000000000 +0100 @@ -0,0 +1,46 @@ +//////////////////////////////////////////////////////////////////////// +// +// RemoteShip.h +// +// Copyright (c) 2003 Nokia Mobile Phones Ltd. All rights reserved. +// +//////////////////////////////////////////////////////////////////////// + +#ifndef __RemoteShip_H__ +#define __RemoteShip_H__ + +#include + +#include + +#include "ShipBase.h" + +class MNetworkSocket; + + + +class CRemoteShip : public CShipBase, public CPacketReceiver::MPRListener +{ +public: + static CRemoteShip* NewL( MNetworkSocket& aConnection, CImageFactory& aImageFactory ); + static CRemoteShip* NewLC( MNetworkSocket& aConnection, CImageFactory& aImageFactory ); + ~CRemoteShip(); + +public: + void Simulate(); + +protected: + /* From MPRListener */ + void OnReceiveComplete( const TDesC8 & aDataPacket ); + void OnReceiveFailed( TInt aReasonCode ); + +protected: + CRemoteShip( MNetworkSocket& aConnection, CImageFactory& aImageFactory ); + void ConstructL(); + +private: + MNetworkSocket& iConnection; + CPacketReceiver* iReceiver; +}; + +#endif diff -i -E -b -w -B -u -r -N -d RetroBlaster/INC/RetroAppUi.h RetroBlasterBt/INC/RetroAppUi.h --- RetroBlaster/INC/RetroAppUi.h 2003-05-26 15:12:38.000000000 +0200 +++ RetroBlasterBt/INC/RetroAppUi.h 2003-11-20 10:56:55.000000000 +0100 @@ -11,12 +11,17 @@ #include +#include + +class CGameProtocol; //class CRetroAppViewOld; class CRetroAppView; +class CTransportClient; +class CTransportServer; -class CRetroAppUi : public CAknAppUi - { +class CRetroAppUi : public CAknAppUi, public MNetworkListener +{ public: void ConstructL(); @@ -29,8 +34,20 @@ void HandleCommandL(TInt aCommand); void DynInitMenuPaneL(TInt aResourceId, CEikMenuPane* aMenuPane); +public: + // from MNetworkListener + void OnNewConnection( MNetworkSocket & aNewConnection ); + void OnConnectFailed( TInt aReasonCode ); + +private: + // For handling the networking stuff.. + CGameProtocol * iProtocol; + private: + CTransportServer* iServer; + CTransportClient* iClient; +private: // CRetroAppViewOld* iAppView; CRetroAppView* iAppView; diff -i -E -b -w -B -u -r -N -d RetroBlaster/INC/RetroAppView.h RetroBlasterBt/INC/RetroAppView.h --- RetroBlaster/INC/RetroAppView.h 2003-05-26 11:54:04.000000000 +0200 +++ RetroBlasterBt/INC/RetroAppView.h 2003-11-20 10:58:36.000000000 +0100 @@ -12,7 +12,6 @@ #include "KeyHandler.h" // Forward Declarations -//class TKeyHandler; class CImageFactory; class CRetroEngine; @@ -33,6 +32,9 @@ TKeyResponse OfferKeyEventL(const TKeyEvent& aKeyEvent,TEventCode aType); public: + CRetroEngine* Engine() const { return iEngine; }; + +public: void StartGameL(); TBool IsPlaying(); void StopGame(); diff -i -E -b -w -B -u -r -N -d RetroBlaster/INC/RetroApplication.h RetroBlasterBt/INC/RetroApplication.h --- RetroBlaster/INC/RetroApplication.h 2003-05-26 10:35:12.000000000 +0200 +++ RetroBlasterBt/INC/RetroApplication.h 2003-11-20 10:59:37.000000000 +0100 @@ -14,6 +14,9 @@ class CRetroApplication : public CAknApplication { public: + ~CRetroApplication(); + +public: // from CEikApplication TUid AppDllUid() const; diff -i -E -b -w -B -u -r -N -d RetroBlaster/INC/RetroBlaster.hrh RetroBlasterBt/INC/RetroBlaster.hrh --- RetroBlaster/INC/RetroBlaster.hrh 2003-05-26 11:23:30.000000000 +0200 +++ RetroBlasterBt/INC/RetroBlaster.hrh 2003-11-19 22:01:16.000000000 +0100 @@ -8,7 +8,8 @@ enum TRetroCommands { - ERetroGameStart = 300, + ERetroGameServer = 300, + ERetroGameClient, ERetroGameStop }; diff -i -E -b -w -B -u -r -N -d RetroBlaster/INC/RetroEngine.h RetroBlasterBt/INC/RetroEngine.h --- RetroBlaster/INC/RetroEngine.h 2003-06-02 16:44:06.000000000 +0200 +++ RetroBlasterBt/INC/RetroEngine.h 2003-11-20 11:06:08.000000000 +0100 @@ -20,12 +20,10 @@ class CTilemap; class MTileset; -class CShipAnim; -class CFireAnim; class CRetroLeafTileset; class CRetroNodeTileset; -class CParticleSystem; -class TVectorFP; +class CShipBase; +class MGameEventListener; class CRetroEngine : public CBase, public MGameTimerObserver, public MDirectScreenAccess { @@ -35,14 +33,21 @@ static CRetroEngine* NewLC(RWsSession& aClient, CWsScreenDevice& aScreenDevice, RWindow& aWindow,TKeyHandler& aKeyHandler, CImageFactory& aImageFactory, const TSize& aSize); ~CRetroEngine(); + // May be NULL to unregister a listener. + void SetGameEventListener( MGameEventListener* aListener ); + void StartGameL(); - void StartFirstGameL(); void StopGame(); // Are we in play inline TBool Playing(){return iPlaying;} + CImageFactory& ImageFactory() const { return iImageFactory; }; + CShipBase* LocalShip() const { return iLocalShip; }; + + void AddNewShipL( CShipBase& aOwnedShip ); + private: TInt DoGameFrame(); void PauseFrame(); @@ -60,7 +65,6 @@ void ConstructSimpleMapL(); void ConstructCompoundMapL(); - void ConstructShipL(); void Simulate(); void UpdatePosition(); @@ -90,28 +94,17 @@ TKeyHandler& iKeyHandler; CImageFactory& iImageFactory; - TPoint iShipScreenPos; - TPoint iShipScreenPosUp4; - TPoint iShipWorldPos; - TPoint iShipVelocity; + // The ships in the game + RArray< CShipBase* > iShips; + + // The ship of the "local" player + CShipBase* iLocalShip; CTilemap* iMap; CRetroLeafTileset* iLeafFactory; CRetroNodeTileset* iNodeFactory; - TRect iShipBounds; TPoint iMapWindowTopLeft; - TInt iShipFrame; - CShipAnim* iShipAnim; - CFireAnim* iFireAnim; - CParticleSystem* iEngineExhaust; - TVectorFP* iShipVectors; - - TInt iThrust; - TInt iGravity; - TInt iDragRatio; - TInt iDragDownshift; - TSize iSize; TBool iDropRenderFrames; @@ -121,5 +114,6 @@ TRect iGameDawingArea; TInt iFrameCounter; + MGameEventListener * iListener; }; #endif \ No newline at end of file diff -i -E -b -w -B -u -r -N -d RetroBlaster/INC/ShipBase.h RetroBlasterBt/INC/ShipBase.h --- RetroBlaster/INC/ShipBase.h 1970-01-01 01:00:00.000000000 +0100 +++ RetroBlasterBt/INC/ShipBase.h 2003-11-20 03:07:59.000000000 +0100 @@ -0,0 +1,67 @@ +//////////////////////////////////////////////////////////////////////// +// +// ShipBase.h +// +// Copyright (c) 2003 Nokia Mobile Phones Ltd. All rights reserved. +// +//////////////////////////////////////////////////////////////////////// + +#ifndef __ShipBase_H__ +#define __ShipBase_H__ + +#include + +class CImageFactory; + +class CFbsBitGc; +class CFireAnim; +class CParticleSystem; +class CShipAnim; +class TVectorFP; + + + +class CShipBase : public CBase +{ + friend class CRetroEngine; + friend class CGameProtocol; + +public: + ~CShipBase(); + +public: + virtual void Simulate() = 0; + virtual void UpdatePosition( TPoint aPixelTopLeft ); + void Render( TPoint aPixelTopLeft, const TRect& aRect, CFbsBitGc* aCallerGc ) const; + +protected: + CShipBase( CImageFactory& aImageFactory ); + void BaseConstructL(); + +protected: + CImageFactory& iImageFactory; + +protected: + TPoint iShipScreenPos; + TPoint iShipScreenPosUp4; + TPoint iShipWorldPos; + TPoint iShipVelocity; + +protected: + TRect iShipBounds; + +protected: + TInt iShipFrame; + CShipAnim* iShipAnim; + CFireAnim* iFireAnim; + CParticleSystem* iEngineExhaust; + TVectorFP* iShipVectors; + +protected: + TInt iThrust; + TInt iGravity; + TInt iDragRatio; + TInt iDragDownshift; +}; + +#endif Binary files RetroBlaster/RETROBLASTER.AIF and RetroBlasterBt/RETROBLASTER.AIF differ Binary files RetroBlaster/RETROBLASTER.MBM and RetroBlasterBt/RETROBLASTER.MBM differ Binary files RetroBlaster/RETROBLASTER.aif and RetroBlasterBt/RETROBLASTER.aif differ Binary files RetroBlaster/RETROBLASTER.mbm and RetroBlasterBt/RETROBLASTER.mbm differ diff -i -E -b -w -B -u -r -N -d RetroBlaster/SRC/GameEventListener.cpp RetroBlasterBt/SRC/GameEventListener.cpp --- RetroBlaster/SRC/GameEventListener.cpp 1970-01-01 01:00:00.000000000 +0100 +++ RetroBlasterBt/SRC/GameEventListener.cpp 2003-11-20 01:18:47.000000000 +0100 @@ -0,0 +1,9 @@ +//////////////////////////////////////////////////////////////////////// +// +// GameEventListener.cpp +// +// Copyright (c) 2003 Nokia Mobile Phones. All rights reserved. +// +//////////////////////////////////////////////////////////////////////// + +#include "GameEventListener.h" diff -i -E -b -w -B -u -r -N -d RetroBlaster/SRC/GameProtocol.cpp RetroBlasterBt/SRC/GameProtocol.cpp --- RetroBlaster/SRC/GameProtocol.cpp 1970-01-01 01:00:00.000000000 +0100 +++ RetroBlasterBt/SRC/GameProtocol.cpp 2003-11-20 03:18:06.000000000 +0100 @@ -0,0 +1,95 @@ +//////////////////////////////////////////////////////////////////////// +// +// GameProtocol.cpp +// +// Copyright (c) 2003 Nokia Mobile Phones. All rights reserved. +// +//////////////////////////////////////////////////////////////////////// + +#include "GameProtocol.h" + +#include "RemoteShip.h" +#include "RetroEngine.h" + +#include +#include + +#include + + + +SYMBIAN_NEW_1_0( CGameProtocol, CRetroEngine & ) + + + +CGameProtocol::CGameProtocol( CRetroEngine & aEngine ) : iEngine( aEngine ) +{ + +} + + + +CGameProtocol::~CGameProtocol() +{ + iEngine.StopGame(); + + delete iSender; iSender = NULL; + iRemoteShips.ResetAndDestroy(); +} + + + +void CGameProtocol::ConstructL() +{ + iEngine.SetGameEventListener( this ); + iEngine.StartGameL(); +} + + + +void CGameProtocol::AddNewConnectionL( MNetworkSocket & aNewConnection ) +{ + if ( iSender == NULL ) + { + iSender = CPacketSender::NewL( aNewConnection, *this ); + } + + CRemoteShip* newShip = CRemoteShip::NewLC( aNewConnection, iEngine.ImageFactory() ); + LEAVE_IF_ERROR( iRemoteShips.Append( newShip ) ); + CleanupStack::Pop(); + + iEngine.AddNewShipL( *newShip ); +} + + + +void CGameProtocol::OnControlTick() +{ + if ( iSender && iSender->CanSend() ) + { + CShipBase* localShip = iEngine.LocalShip(); + + iSendBuffer.Zero(); + NMarshalling::ExternalizeTInt( iSendBuffer, localShip->iShipFrame ); + NMarshalling::ExternalizeTInt( iSendBuffer, localShip->iShipScreenPos.iX ); + NMarshalling::ExternalizeTInt( iSendBuffer, localShip->iShipScreenPos.iY ); + NMarshalling::ExternalizeTInt( iSendBuffer, localShip->iShipWorldPos.iX ); + NMarshalling::ExternalizeTInt( iSendBuffer, localShip->iShipWorldPos.iY ); + + iSender->SendData( iSendBuffer ); + } +} + + + +void CGameProtocol::OnSendComplete() +{ + +} + + + +void CGameProtocol::OnSendFailed( TInt aReasonCode ) +{ + LOG_IF_ERROR( "OnSendFailed", aReasonCode ); +} diff -i -E -b -w -B -u -r -N -d RetroBlaster/SRC/LocalShip.cpp RetroBlasterBt/SRC/LocalShip.cpp --- RetroBlaster/SRC/LocalShip.cpp 1970-01-01 01:00:00.000000000 +0100 +++ RetroBlasterBt/SRC/LocalShip.cpp 2003-11-20 03:09:34.000000000 +0100 @@ -0,0 +1,133 @@ +//////////////////////////////////////////////////////////////////////// +// +// LocalShip.cpp +// +// Copyright (c) 2003 Nokia Mobile Phones Ltd. All rights reserved. +// +//////////////////////////////////////////////////////////////////////// + +#include "LocalShip.h" + +//System includes +#include + +//User includes +#include "KeyHandler.h" +#include "ImageFactory.h" +#include "RenderableFactory.h" +#include "BaseAnim.h" +#include "FireAnim.h" +#include "ParticleSystem.h" +#include "ShipAnim.h" + + + +CLocalShip* CLocalShip::NewLC( TKeyHandler& aKeyHandler, CImageFactory& aImageFactory ) +{ + CLocalShip* self = new ( ELeave ) CLocalShip( aKeyHandler, aImageFactory ); + CleanupStack::PushL(self); + self->ConstructL(); + return self; +} + +CLocalShip* CLocalShip::NewL( TKeyHandler& aKeyHandler, CImageFactory& aImageFactory ) +{ + CLocalShip* self = CLocalShip::NewLC( aKeyHandler, aImageFactory ); + CleanupStack::Pop(); + return self; +} + + + +CLocalShip::CLocalShip( TKeyHandler& aKeyHandler, CImageFactory& aImageFactory ) +: CShipBase( aImageFactory ), iKeyHandler( aKeyHandler ) +{ + +} + + + +CLocalShip::~CLocalShip() +{ + +} + + + +void CLocalShip::ConstructL() +{ + BaseConstructL(); +} + + + +void CLocalShip::Simulate() +{ + iEngineExhaust->Simulate(); + + if( iKeyHandler.Direction() == TKeyHandler::ELeft ) + { + iShipFrame--; + } + else if ( iKeyHandler.Direction() == TKeyHandler::ERight ) + { + iShipFrame++; + } + + if (iKeyHandler.FirePressed()) + { + iEngineExhaust->Generate(iShipWorldPos,iShipVectors[iShipFrame],iShipVelocity,13 << 4,128); + + TPoint deltaV = iShipVectors[iShipFrame].ScaleToPoint(-iThrust); + iShipVelocity += deltaV; + } + + iShipFrame &= 0x3f; + + TInt vSquared = ( iShipVelocity.iX * iShipVelocity.iX ) + ( iShipVelocity.iY * iShipVelocity.iY ); + + TInt dragRatio = iDragRatio; + + if ( vSquared < 1024 ) + { + // Very slow - no drag needed: + dragRatio = 0x0100; + } + else if ( vSquared > 4096 ) + { + // Fast - apply strong drag: + dragRatio = 0x00fc; + } + else if ( vSquared > 8192 ) + { + // Very fast - apply stronger drag: + dragRatio = 0x00f0; + } + + if ( vSquared > 1024 ) + { + iShipVelocity.iX = ( iShipVelocity.iX * dragRatio ) >> iDragDownshift; + iShipVelocity.iY = ( iShipVelocity.iY * dragRatio ) >> iDragDownshift; + } + + iShipVelocity.iY += iGravity; + + TPoint newWorldPos = iShipWorldPos + iShipVelocity; + + if ( iShipBounds.Contains(newWorldPos) ) + { + iShipWorldPos = newWorldPos; + } + else + { + if ( ( newWorldPos.iX < iShipBounds.iTl.iX ) || ( newWorldPos.iX >= iShipBounds.iBr.iX ) ) + { + iShipVelocity.iX = -iShipVelocity.iX; + } + + if ( ( newWorldPos.iY < iShipBounds.iTl.iY ) || ( newWorldPos.iY >= iShipBounds.iBr.iY ) ) + { + iShipVelocity.iY = -iShipVelocity.iY; + } + } +} diff -i -E -b -w -B -u -r -N -d RetroBlaster/SRC/RemoteShip.cpp RetroBlasterBt/SRC/RemoteShip.cpp --- RetroBlaster/SRC/RemoteShip.cpp 1970-01-01 01:00:00.000000000 +0100 +++ RetroBlasterBt/SRC/RemoteShip.cpp 2003-11-20 03:03:51.000000000 +0100 @@ -0,0 +1,92 @@ +//////////////////////////////////////////////////////////////////////// +// +// RemoteShip.cpp +// +// Copyright (c) 2003 Nokia Mobile Phones Ltd. All rights reserved. +// +//////////////////////////////////////////////////////////////////////// + +#include "RemoteShip.h" + +//System includes +#include + +#include + +#include + +//User includes +#include "KeyHandler.h" +#include "ImageFactory.h" +#include "RenderableFactory.h" +#include "BaseAnim.h" +#include "FireAnim.h" +#include "ParticleSystem.h" +#include "ShipAnim.h" + + + +CRemoteShip* CRemoteShip::NewLC( MNetworkSocket& aConnection, CImageFactory& aImageFactory ) +{ + CRemoteShip* self = new ( ELeave ) CRemoteShip( aConnection, aImageFactory ); + CleanupStack::PushL(self); + self->ConstructL(); + return self; +} + +CRemoteShip* CRemoteShip::NewL( MNetworkSocket& aConnection, CImageFactory& aImageFactory ) +{ + CRemoteShip* self = CRemoteShip::NewLC( aConnection, aImageFactory ); + CleanupStack::Pop(); + return self; +} + + + +CRemoteShip::CRemoteShip( MNetworkSocket& aConnection, CImageFactory& aImageFactory ) +: CShipBase( aImageFactory ), iConnection( aConnection ) +{ + +} + + + +CRemoteShip::~CRemoteShip() +{ + delete iReceiver; iReceiver = NULL; +} + + + +void CRemoteShip::ConstructL() +{ + BaseConstructL(); + + iReceiver = CPacketReceiver::NewL( iConnection, *this ); +} + + + +void CRemoteShip::Simulate() +{ + +} + + + +void CRemoteShip::OnReceiveComplete( const TDesC8 & aDataPacket ) +{ + TInt offset = 0; + iShipFrame = NMarshalling::InternalizeTInt( aDataPacket, offset ); + iShipScreenPos.iX = NMarshalling::InternalizeTInt( aDataPacket, offset ); + iShipScreenPos.iY = NMarshalling::InternalizeTInt( aDataPacket, offset ); + iShipWorldPos.iX = NMarshalling::InternalizeTInt( aDataPacket, offset ); + iShipWorldPos.iY = NMarshalling::InternalizeTInt( aDataPacket, offset ); +} + + + +void CRemoteShip::OnReceiveFailed( TInt aReasonCode ) +{ + LOG_IF_ERROR( "OnReceiveFailed", aReasonCode ); +} diff -i -E -b -w -B -u -r -N -d RetroBlaster/SRC/RetroAppUi.cpp RetroBlasterBt/SRC/RetroAppUi.cpp --- RetroBlaster/SRC/RetroAppUi.cpp 2003-06-02 16:24:06.000000000 +0200 +++ RetroBlasterBt/SRC/RetroAppUi.cpp 2003-11-20 11:10:52.000000000 +0100 @@ -6,10 +6,19 @@ // //////////////////////////////////////////////////////////////////////// +#include "RetroAppUi.h" + #include #include -#include "RetroAppUi.h" +#include +#include + +#include +#include +#include + +#include "GameProtocol.h" #include "RetroAppView.h" #include "Retroblaster.h" //#include "Retroblaster_AppView.h" @@ -47,6 +56,8 @@ delete iAppView; iAppView = NULL; } + delete iServer; iServer = NULL; + delete iClient; iClient = NULL; } // Handle any menu commands: @@ -58,11 +69,22 @@ case EAknSoftkeyExit: Exit(); break; - case ERetroGameStart: - static_cast(iAppView)->StartGameL(); + case ERetroGameServer: + MAKE_SURE( iServer == NULL && iClient == NULL && iProtocol == NULL ); + iServer = NNetworkFactory::CreateServerL( *this ); + iServer->StartL(); + iProtocol = CGameProtocol::NewL( *iAppView->Engine() ); + break; + case ERetroGameClient: + MAKE_SURE( iServer == NULL && iClient == NULL && iProtocol == NULL ); + iClient = NNetworkFactory::CreateClientL( *this ); + iClient->ConnectL(); + iProtocol = CGameProtocol::NewL( *iAppView->Engine() ); break; case ERetroGameStop: - static_cast(iAppView)->StopGame(); + delete iProtocol; iProtocol = NULL; + delete iClient; iClient = NULL; + delete iServer; iServer = NULL; break; default: break; @@ -77,15 +99,26 @@ { if (aResourceId == R_RETRO_MENUPANE) { - if (static_cast(iAppView)->IsPlaying()) - { - aMenuPane->SetItemDimmed(ERetroGameStart, ETrue); - aMenuPane->SetItemDimmed(ERetroGameStop, EFalse); + aMenuPane->SetItemDimmed(ERetroGameServer, ( iServer || iClient ) ); + aMenuPane->SetItemDimmed(ERetroGameClient, ( iServer || iClient ) ); + aMenuPane->SetItemDimmed(ERetroGameStop, !( iServer || iClient )); } - else - { - aMenuPane->SetItemDimmed(ERetroGameStart, EFalse); - aMenuPane->SetItemDimmed(ERetroGameStop, ETrue); } + + + +void CRetroAppUi::OnNewConnection( MNetworkSocket & aNewConnection ) +{ + TRAPD( error, iProtocol->AddNewConnectionL( aNewConnection ) ); + LOG_IF_ERROR( "Failed processing new connection", error ); } + + + +void CRetroAppUi::OnConnectFailed( TInt aReasonCode ) +{ + TBuf< 64 > temp; + temp.Copy( ERROR_STRING_L8( aReasonCode ) ); + + iEikonEnv->AlertWin( _L( "Connection failed" ), temp ); } diff -i -E -b -w -B -u -r -N -d RetroBlaster/SRC/RetroAppView.cpp RetroBlasterBt/SRC/RetroAppView.cpp --- RetroBlaster/SRC/RetroAppView.cpp 2003-06-02 16:24:06.000000000 +0200 +++ RetroBlasterBt/SRC/RetroAppView.cpp 2003-11-20 11:12:16.000000000 +0100 @@ -50,7 +50,6 @@ // Activate the window, which makes it ready to be drawn ActivateL(); - iEngine->StartFirstGameL(); } CRetroAppView::CRetroAppView() : @@ -105,6 +104,7 @@ iKeyHandler.RightPressed(); returnKey = EKeyWasConsumed; break; + case EStdKeySpace: case EStdKeyDevice3: iKeyHandler.PressedFire(); returnKey = EKeyWasConsumed; @@ -125,6 +125,7 @@ iKeyHandler.NoDirection(); returnKey = EKeyWasConsumed; break; + case EStdKeySpace: case EStdKeyDevice3: iKeyHandler.FireReleased(); returnKey = EKeyWasConsumed; diff -i -E -b -w -B -u -r -N -d RetroBlaster/SRC/RetroApplication.cpp RetroBlasterBt/SRC/RetroApplication.cpp --- RetroBlaster/SRC/RetroApplication.cpp 2003-06-02 16:24:06.000000000 +0200 +++ RetroBlasterBt/SRC/RetroApplication.cpp 2003-11-20 11:13:07.000000000 +0100 @@ -9,10 +9,29 @@ #include "RetroDocument.h" #include "RetroApplication.h" +#include +#include +#include + static const TUid KUidRetroApp = {0x0fedface}; + + +CRetroApplication::~CRetroApplication() +{ + CStaticData::Dismiss(); +} + + + CApaDocument* CRetroApplication::CreateDocumentL() { + CLogging::InitL( _L( "RetroBlaster.log" ) ); + +#if defined(__WINS__) + CSystemSettings::Static()->SetSocketMode( CSystemSettings::EWin32Sockets ); +#endif + CApaDocument* document = CRetroDocument::NewL(*this); return document; } diff -i -E -b -w -B -u -r -N -d RetroBlaster/SRC/RetroEngine.cpp RetroBlasterBt/SRC/RetroEngine.cpp --- RetroBlaster/SRC/RetroEngine.cpp 2003-06-02 16:29:06.000000000 +0200 +++ RetroBlasterBt/SRC/RetroEngine.cpp 2003-11-20 11:18:38.000000000 +0100 @@ -11,6 +11,8 @@ //System includes #include +#include + //User includes #include "KeyHandler.h" #include "ImageFactory.h" @@ -27,6 +29,10 @@ #include "Tilemap.h" #include "Tileset.h" #include "GameTimer.h" +#include "LocalShip.h" +#include "GameEventListener.h" + + //////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////// @@ -74,10 +80,14 @@ // ConstructSimpleMapL(); ConstructCompoundMapL(); - ConstructShipL(); iDoubleBufferedArea = CDoubleBufferedArea::NewL(iSize, EColor4K); iOffscreenContext = &(iDoubleBufferedArea->GetDoubleBufferedAreaContext()); + + LEAVE_IF_ERROR( iShips.Append( CLocalShip::NewLC( iKeyHandler, iImageFactory ) ) ); + CleanupStack::Pop(); + + iLocalShip = iShips[ 0 ]; } //////////////////////////////////////////////////////////////////////// @@ -102,17 +112,7 @@ delete iLeafFactory; iLeafFactory = NULL; - delete iEngineExhaust; - iEngineExhaust = NULL; - - delete[] iShipVectors; - iShipVectors = NULL; - - delete iShipAnim; - iShipAnim = NULL; - - delete iFireAnim; - iFireAnim = NULL; + iShips.Reset(); } //////////////////////////////////////////////////////////////////////// @@ -139,10 +139,6 @@ 4,0,4,0,4,0,4,0,4,0,4,0,4,0,4,0, }; - iShipBounds = TRect(TPoint(0x00000800,0x00000800),TPoint(0x00001800,0x00001800)); - iShipWorldPos = iShipBounds.Center(); - iShipVelocity = TPoint(0x000e,0x0013); - iLeafFactory = CRetroLeafTileset::NewL(iImageFactory.TileImage()); iMap = CTilemap::NewL(16,16,&mapData[0],*iLeafFactory); } @@ -171,9 +167,6 @@ 15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15, }; - iShipBounds = TRect(TPoint(0x00000800,0x00000800),TPoint(0x00007800,0x00007800)); - iShipWorldPos = iShipBounds.Center(); - iLeafFactory = CRetroLeafTileset::NewL(iImageFactory.TileImage()); iNodeFactory = CRetroNodeTileset::NewL(*iLeafFactory); iMap = CTilemap::NewL(16,16,&mapData[0],*iNodeFactory); @@ -181,141 +174,22 @@ //////////////////////////////////////////////////////////////////////// -void CRetroEngine::ConstructShipL() - { - iShipVelocity = -TPoint(0x000e,0x0013); - - iShipFrame = 8; - iShipScreenPos = TPoint(88,104); - iShipScreenPosUp4 = TPoint(iShipScreenPos.iX << 4, iShipScreenPos.iY << 4); - - iShipAnim = CShipAnim::NewL(iImageFactory.ShipAnim()); - iFireAnim = CFireAnim::NewL(iImageFactory.FireAnim()); - - iEngineExhaust = CParticleSystem::NewL(16,*iFireAnim); - - // Physics parameters for ship motion: - iDragDownshift = 8; - iDragRatio = 0xff; - iThrust = 6; - iGravity = 1; - - - // Allocate and initialise ship vectors - // (each one a vector lying along the central axis of the ship - // in the corresponding animation frame): - iShipVectors = new TVectorFP[64]; - User::LeaveIfNull(iShipVectors); - - TReal degreesToRadians = 3.141592 / 180.0; - - // Animation frame #0 is at 45 degrees, so: - TReal angle = 45.0 * degreesToRadians; - TReal angleStep = ( 360.0 / 64.0 ) * degreesToRadians; - - for ( TInt frame = 0 ; frame < 64 ; frame++ ) - { - TReal cos; - TReal sin; - - Math::Cos(cos,angle); - Math::Sin(sin,angle); - - TInt16 cosFP; - TInt16 sinFP; - - Math::Int(cosFP,cos * 256.0); - Math::Int(sinFP,sin * 256.0); - - iShipVectors[frame] = TVectorFP(TPoint(cosFP,sinFP)); - - angle += angleStep; - } - } - -//////////////////////////////////////////////////////////////////////// - void CRetroEngine::Simulate() { UpdatePosition(); - iEngineExhaust->Simulate(); - if( iKeyHandler.Direction() == TKeyHandler::ELeft ) - { - iShipFrame--; - } - else if ( iKeyHandler.Direction() == TKeyHandler::ERight ) - { - iShipFrame++; - } - - if (iKeyHandler.FirePressed()) - { - iEngineExhaust->Generate(iShipWorldPos,iShipVectors[iShipFrame],iShipVelocity,13 << 4,128); - } - - iShipFrame &= 0x3f; + for ( TInt idx = 0; idx < iShips.Count(); idx++ ) + iShips[ idx ]->Simulate(); } //////////////////////////////////////////////////////////////////////// void CRetroEngine::UpdatePosition() { + iMapWindowTopLeft = iLocalShip->iShipWorldPos - iLocalShip->iShipScreenPosUp4; - if (iKeyHandler.FirePressed()) - { - TPoint deltaV = iShipVectors[iShipFrame].ScaleToPoint(-iThrust); - iShipVelocity += deltaV; - } - - TInt vSquared = ( iShipVelocity.iX * iShipVelocity.iX ) + ( iShipVelocity.iY * iShipVelocity.iY ); - - TInt dragRatio = iDragRatio; - - if ( vSquared < 1024 ) - { - // Very slow - no drag needed: - dragRatio = 0x0100; - } - else if ( vSquared > 4096 ) - { - // Fast - apply strong drag: - dragRatio = 0x00fc; - } - else if ( vSquared > 8192 ) - { - // Very fast - apply stronger drag: - dragRatio = 0x00f0; - } - - if ( vSquared > 1024 ) - { - iShipVelocity.iX = ( iShipVelocity.iX * dragRatio ) >> iDragDownshift; - iShipVelocity.iY = ( iShipVelocity.iY * dragRatio ) >> iDragDownshift; - } - - iShipVelocity.iY += iGravity; - - TPoint newWorldPos = iShipWorldPos + iShipVelocity; - - if ( iShipBounds.Contains(newWorldPos) ) - { - iShipWorldPos = newWorldPos; - } - else - { - if ( ( newWorldPos.iX < iShipBounds.iTl.iX ) || ( newWorldPos.iX >= iShipBounds.iBr.iX ) ) - { - iShipVelocity.iX = -iShipVelocity.iX; - } - - if ( ( newWorldPos.iY < iShipBounds.iTl.iY ) || ( newWorldPos.iY >= iShipBounds.iBr.iY ) ) - { - iShipVelocity.iY = -iShipVelocity.iY; - } - } - - iMapWindowTopLeft = iShipWorldPos - iShipScreenPosUp4; + for ( TInt idx = 0; idx < iShips.Count(); idx++ ) + iShips[ idx ]->UpdatePosition( iMapWindowTopLeft ); } //////////////////////////////////////////////////////////////////////// @@ -325,9 +199,10 @@ TPoint pixelTopLeft(iMapWindowTopLeft.iX >> 4,iMapWindowTopLeft.iY >> 4); iMap->Render(pixelTopLeft,aRect,aCallerGc); - - iEngineExhaust->Render(pixelTopLeft,aRect,aCallerGc); - iShipAnim->RenderFrameCentered(iShipFrame,iShipScreenPos,aRect,aCallerGc); + for ( TInt idx = 0; idx < iShips.Count(); idx++ ) + { + iShips[ idx ]->Render( pixelTopLeft, aRect, aCallerGc ); + } } //////////////////////////////////////////////////////////////////////// @@ -342,6 +217,7 @@ // Get region that DSA can draw in iRegion = iDirectScreenAccess->DrawingRegion(); + iGameDawingArea = iRegion->BoundingRect(); // Set the display to clip to this region iGc->SetClippingRegion(iRegion); @@ -349,16 +225,6 @@ //////////////////////////////////////////////////////////////////////// -void CRetroEngine::StartFirstGameL() - { - StartGameL(); - // We only want to play the game if we have the whole screen available so - // on first start we record the region available for comparision later (in restart) - iGameDawingArea = iRegion->BoundingRect(); - } - -//////////////////////////////////////////////////////////////////////// - void CRetroEngine::StartGameL() { iPaused = EFalse; @@ -387,6 +253,11 @@ // Force screen update: iDirectScreenAccess->ScreenDevice()->Update(); + if ( iListener ) + { + iListener->OnControlTick(); + } + Simulate(); // Drop 1 render frame in every 128, to avoid ViewSrv 11 problems: @@ -422,8 +293,6 @@ SetupDirectScreenAccessL(); if(iPaused) { - if(iGameDawingArea == iRegion->BoundingRect()) - { iPaused = EFalse; if(!iGameTimer->IsActive()) { @@ -432,11 +301,6 @@ } else { - PauseFrame(); - } - } - else - { if(!iGameTimer->IsActive()) { iGameTimer->Restart(); @@ -470,3 +334,14 @@ //////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////// +void CRetroEngine::SetGameEventListener( MGameEventListener* aListener ) +{ + iListener = aListener; +} + + + +void CRetroEngine::AddNewShipL( CShipBase& aShip ) +{ + LEAVE_IF_ERROR( iShips.Append( &aShip ) ); +} diff -i -E -b -w -B -u -r -N -d RetroBlaster/SRC/ShipBase.cpp RetroBlasterBt/SRC/ShipBase.cpp --- RetroBlaster/SRC/ShipBase.cpp 1970-01-01 01:00:00.000000000 +0100 +++ RetroBlasterBt/SRC/ShipBase.cpp 2003-11-20 03:25:04.000000000 +0100 @@ -0,0 +1,127 @@ +//////////////////////////////////////////////////////////////////////// +// +// ShipBase.cpp +// +// Copyright (c) 2003 Nokia Mobile Phones Ltd. All rights reserved. +// +//////////////////////////////////////////////////////////////////////// + +#include "ShipBase.h" + +//System includes +#include + +#include + +//User includes +#include "ImageFactory.h" +#include "RenderableFactory.h" +#include "BaseAnim.h" +#include "FireAnim.h" +#include "ParticleSystem.h" +#include "ShipAnim.h" + + + +CShipBase::CShipBase( CImageFactory& aImageFactory ) : iImageFactory( aImageFactory ) +{ + +} + + + +CShipBase::~CShipBase() +{ + delete iEngineExhaust; + iEngineExhaust = NULL; + + delete[] iShipVectors; + iShipVectors = NULL; + + delete iShipAnim; + iShipAnim = NULL; + + delete iFireAnim; + iFireAnim = NULL; +} + + + +void CShipBase::BaseConstructL() +{ + iShipBounds = TRect(TPoint(0x00000800,0x00000800),TPoint(0x00007800,0x00007800)); + iShipWorldPos = iShipBounds.Center(); + iShipVelocity = TPoint(0,0); + + iShipFrame = 8; + iShipScreenPos = TPoint(88,104); + iShipScreenPosUp4 = TPoint(iShipScreenPos.iX << 4, iShipScreenPos.iY << 4); + + iShipAnim = CShipAnim::NewL(iImageFactory.ShipAnim()); + iFireAnim = CFireAnim::NewL(iImageFactory.FireAnim()); + + iEngineExhaust = CParticleSystem::NewL(16,*iFireAnim); + + // Physics parameters for ship motion: + iDragDownshift = 8; + iDragRatio = 0xff; + iThrust = 6; + iGravity = 0; + + // Allocate and initialise ship vectors + // (each one a vector lying along the central axis of the ship + // in the corresponding animation frame): + iShipVectors = new TVectorFP[64]; + User::LeaveIfNull(iShipVectors); + + TReal degreesToRadians = 3.141592 / 180.0; + + // Animation frame #0 is at 45 degrees, so: + TReal angle = 45.0 * degreesToRadians; + TReal angleStep = ( 360.0 / 64.0 ) * degreesToRadians; + + for ( TInt frame = 0 ; frame < 64 ; frame++ ) + { + TReal cos; + TReal sin; + + Math::Cos(cos,angle); + Math::Sin(sin,angle); + + TInt16 cosFP; + TInt16 sinFP; + + Math::Int(cosFP,cos * 256.0); + Math::Int(sinFP,sin * 256.0); + + iShipVectors[frame] = TVectorFP(TPoint(cosFP,sinFP)); + + angle += angleStep; + } +} + + + +void CShipBase::UpdatePosition( TPoint aPixelTopLeft ) +{ + iShipScreenPos = iShipWorldPos; + iShipScreenPos.iX -= aPixelTopLeft.iX; + iShipScreenPos.iY -= aPixelTopLeft.iY; + iShipScreenPos.iX >>= 4; + iShipScreenPos.iY >>= 4; + + iShipScreenPosUp4 = TPoint(iShipScreenPos.iX << 4, iShipScreenPos.iY << 4); +} + + + +void CShipBase::Render( TPoint aPixelTopLeft, const TRect& aRect,CFbsBitGc* aCallerGc ) const +{ + TPoint screenPos( aPixelTopLeft.iX >> 4, aPixelTopLeft.iY >> 4 ); + screenPos.iX -= iShipWorldPos.iX >> 8; + screenPos.iY -= iShipWorldPos.iY >> 8; + screenPos += iShipScreenPos; + + iEngineExhaust->Render( aPixelTopLeft, aRect, aCallerGc ); + iShipAnim->RenderFrameCentered( iShipFrame, screenPos, aRect, aCallerGc ); +}