Skip to content

Commit

Permalink
I think I've solved the crash issues that occurred on map change
Browse files Browse the repository at this point in the history
  • Loading branch information
Ohmnivore committed Jun 14, 2014
1 parent f1717f2 commit d8dfacf
Show file tree
Hide file tree
Showing 22 changed files with 240 additions and 75 deletions.
Binary file modified Client/export/windows/cpp/bin/SkullRush.exe
Binary file not shown.
2 changes: 1 addition & 1 deletion Client/export/windows/cpp/bin/config.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version=0.3.6
version=0.3.7
name=NOOB
team=1
ip=
Expand Down
6 changes: 3 additions & 3 deletions Client/source/Downloader.hx
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class Downloader
switch (event.type)
{
case LoaderEventType.Fail(error):
Reg.state.downloadError(error);
Reg.pre_state.downloadError(error);

case LoaderEventType.Complete:
//Start sub-manifest downloading
Expand Down Expand Up @@ -88,7 +88,7 @@ class Downloader
switch (event.type)
{
case LoaderEventType.Fail(error):
Reg.state.downloadError(error);
Reg.pre_state.downloadError(error);


case LoaderEventType.Complete:
Expand Down Expand Up @@ -203,7 +203,7 @@ class Downloader
switch (event.type)
{
case LoaderEventType.Fail(error):
Reg.state.downloadError(error);
Reg.pre_state.downloadError(error);


case LoaderEventType.Complete:
Expand Down
95 changes: 61 additions & 34 deletions Client/source/PlayState.hx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import flixel.util.FlxAngle;
import flixel.util.FlxMath;
import flixel.util.FlxPoint;
import flixel.util.FlxRect;
import flixel.util.FlxTimer;
import flixel.util.FlxVector;
import haxe.io.Bytes;
import haxe.macro.Expr.Function;
Expand Down Expand Up @@ -53,7 +54,6 @@ class PlayState extends FlxState
public var scores:NScoreManager;

public var player:Player;
public var playermap:Map<Int, Player>;

public var ping_text:FlxText;
public var teams:Array<Team>;
Expand All @@ -68,21 +68,21 @@ class PlayState extends FlxState

public var cross:FlxCrosshairs;

//public var buffer_string:String;
public var buffer_string:String;

public function new(BufferString:String = null)
{
super();

//buffer_string = BufferString;
buffer_string = BufferString;
}

/**
* Function that is called up when to state is created to set it up.
*/
override public function create():Void
{
SkullClient.initClient();
//SkullClient.initClient();

persistentDraw = true;
persistentUpdate = true;
Expand All @@ -98,7 +98,7 @@ class PlayState extends FlxState

super.create();
Reg.state = this;
playermap = new Map<Int, Player>();
//playermap = new Map<Int, Player>();

background = new FlxGroup();
add(background);
Expand Down Expand Up @@ -155,15 +155,42 @@ class PlayState extends FlxState
//wepBar = new WeaponBar(2);
//hud.add(wepBar);

Assets.initAssets();
Thread.create(thread);
SkullClient.execute = true;
//Assets.initAssets();
//Thread.create(thread);
//new FlxTimer(10, delayedThread);

m = new Mutex();

//if (buffer_string != null)
//{
//loadMap("Test", buffer_string);
loadMap("Test", buffer_string);
//}

for (i in Reg.playermap.keys())
{
var p:Player = Reg.playermap.get(i);

var p_new:Player;
p_new = new Player(p.ID, p.name, 50, 50);

Reg.playermap.set(i, p_new);

if (p_new.ID == Reg.playerID)
{
Reg.state.player = p_new;

FlxG.camera.follow(Reg.state.player);
FlxG.camera.followLerp = 30.0;
}
}

new FlxTimer(5, delayedThread);
}

public function delayedThread(T:FlxTimer):Void
{
Thread.create(thread);
}

public function sendChatMsg():Void
Expand Down Expand Up @@ -199,17 +226,17 @@ class PlayState extends FlxState
}
}

public function onLoaded():Void
{
trace("Loaded external assets.");
//public function onLoaded():Void
//{
//trace("Loaded external assets.");
//if (buffer_string == null)
//{
Msg.PlayerInfo.data.set("name", Assets.config.get("name"));
Msg.PlayerInfo.data.set("team", Assets.config.get("team"));

Reg.client.send(Msg.PlayerInfo.ID, 1, ENet.ENET_PACKET_FLAG_RELIABLE);
//Msg.PlayerInfo.data.set("name", Assets.config.get("name"));
//Msg.PlayerInfo.data.set("team", Assets.config.get("team"));
//
//Reg.client.send(Msg.PlayerInfo.ID, 1, ENet.ENET_PACKET_FLAG_RELIABLE);
//}
}
//}

public function loadMap(MapName:String, MapString:String):Void
{
Expand Down Expand Up @@ -284,7 +311,7 @@ class PlayState extends FlxState
//trailArea.y = collidemap.y - FlxG.height / 2;
//trailArea.setSize(collidemap.width + FlxG.width, collidemap.height + FlxG.height);

for (p in playermap.iterator())
for (p in Reg.playermap.iterator())
{
var pl:Player = p;

Expand All @@ -306,23 +333,23 @@ class PlayState extends FlxState
}
}

public function downloadError(e:LoaderErrorType):Void
{
switch (e)
{
case LoaderErrorType.Data:


case LoaderErrorType.Format:


case LoaderErrorType.IO:


case LoaderErrorType.Security:

}
}
//public function downloadError(e:LoaderErrorType):Void
//{
//switch (e)
//{
//case LoaderErrorType.Data:
//
//
//case LoaderErrorType.Format:
//
//
//case LoaderErrorType.IO:
//
//
//case LoaderErrorType.Security:
//
//}
//}

/**
* Function that is called when this state is destroyed - you might want to
Expand Down
1 change: 1 addition & 0 deletions Client/source/Player.hx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class Player extends PlayerBase
public function new(Id:Int, Name:String, X:Int, Y:Int)
{
super(Id, Name, X, Y);
trace("newplayer");
setGun(1);
}

Expand Down
68 changes: 68 additions & 0 deletions Client/source/PreGame.hx
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package ;
import flixel.FlxState;
import mloader.Loader.LoaderErrorType;
import enet.ENet;

/**
* ...
* @author Ohmnivore
*/

class PreGame extends FlxState
{

public function new()
{
super();
}

override public function create():Void
{
super.create();

Reg.pre_state = this;
Reg.playermap = new Map<Int, Player>();

Assets.initAssets();

SkullClient.initClient();
}

public function onLoaded():Void
{
trace("Loaded external assets.");
//if (buffer_string == null)
//{
Msg.PlayerInfo.data.set("name", Assets.config.get("name"));
Msg.PlayerInfo.data.set("team", Assets.config.get("team"));

Reg.client.send(Msg.PlayerInfo.ID, 1, ENet.ENET_PACKET_FLAG_RELIABLE);
//}
}

public function downloadError(e:LoaderErrorType):Void
{
switch (e)
{
case LoaderErrorType.Data:


case LoaderErrorType.Format:


case LoaderErrorType.IO:


case LoaderErrorType.Security:

}
}

override public function update():Void
{
super.update();

Reg.client.poll();
}

}
39 changes: 28 additions & 11 deletions Client/source/SkullClient.hx
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ class SkullClient extends Client
public static var execute:Bool = false;
public static var init:Bool = false;

private var old_msg:Int = -1;

public static function initClient():Void
{
if (!init)
Expand Down Expand Up @@ -134,25 +136,31 @@ class SkullClient extends Client
{
super.onReceive(MsgID, E);

//if (old_msg != MsgID)
//trace(MsgID);
//old_msg = MsgID;

if (MsgID == Msg.Manifest.ID)
{
if (Msg.Manifest.data.get("url") == "null")
{
Reg.state.onLoaded();
Reg.pre_state.onLoaded();
}
else
{
var d:Downloader = new Downloader(Msg.Manifest.data.get("url"));
d.whenfinished = Reg.state.onLoaded;
d.whenfinished = Reg.pre_state.onLoaded;
}
}

if (MsgID == Msg.MapMsg.ID)
{
//if (Reg.state.collidemap != null)
//FlxG.switchState(new PlayState());
Reg.state.loadMap(Msg.MapMsg.data.get("mapname"), Msg.MapMsg.data.get("mapstring"));
//FlxG.switchState(new PlayState(Msg.MapMsg.data.get("mapstring")));
//Reg.state.loadMap(Msg.MapMsg.data.get("mapname"), Msg.MapMsg.data.get("mapstring"));
//trace(Msg.MapMsg.data.get("mapstring"));
SkullClient.execute = false;
FlxG.switchState(new PlayState(Msg.MapMsg.data.get("mapstring")));
}

if (MsgID == Msg.PlayerInfoBack.ID)
Expand All @@ -162,10 +170,13 @@ class SkullClient extends Client
50,
50);

Reg.playerID = Reg.state.player.ID;

Reg.state.player.setColor(Msg.PlayerInfoBack.data.get("color"),
Msg.PlayerInfoBack.data.get("graphic"));

Reg.state.playermap.set(Reg.state.player.ID, Reg.state.player);
//Reg.state.playermap.set(Reg.state.player.ID, Reg.state.player);
Reg.playermap.set(Reg.state.player.ID, Reg.state.player);

FlxG.camera.follow(Reg.state.player);
FlxG.camera.followLerp = 30.0;
Expand All @@ -181,16 +192,19 @@ class SkullClient extends Client
p.setColor(Msg.PlayerInfoAnnounce.data.get("color"),
Msg.PlayerInfoAnnounce.data.get("graphic"));

Reg.state.playermap.set(p.ID, p);
//Reg.state.playermap.set(p.ID, p);
Reg.playermap.set(p.ID, p);
}

if (MsgID == Msg.PlayerDisco.ID)
{
var p:Player = Reg.state.playermap.get(Msg.PlayerDisco.data.get("id"));
//var p:Player = Reg.state.playermap.get(Msg.PlayerDisco.data.get("id"));
var p:Player = Reg.playermap.get(Msg.PlayerDisco.data.get("id"));

if (p != null)
{
Reg.state.playermap.remove(Msg.PlayerDisco.data.get("id"));
//Reg.state.playermap.remove(Msg.PlayerDisco.data.get("id"));
Reg.playermap.remove(Msg.PlayerDisco.data.get("id"));

p.kill();
}
Expand All @@ -210,7 +224,8 @@ class SkullClient extends Client
{
if (parr[0] != null)
{
var p:Player = Reg.state.playermap.get(parr[0]);
//var p:Player = Reg.state.playermap.get(parr[0]);
var p:Player = Reg.playermap.get(parr[0]);

if (p != null)
{
Expand Down Expand Up @@ -502,7 +517,8 @@ class SkullClient extends Client

if (MsgID == Msg.SetAppearance.ID)
{
var p:Player = Reg.state.playermap.get(Msg.SetAppearance.data.get("id"));
//var p:Player = Reg.state.playermap.get(Msg.SetAppearance.data.get("id"));
var p:Player = Reg.playermap.get(Msg.SetAppearance.data.get("id"));

if (p != null)
{
Expand Down Expand Up @@ -604,7 +620,8 @@ class SkullClient extends Client
{
NWeapon.addWeapon(new NWeapon(map.get(slot)), slot + 1);
}
for (p in Reg.state.playermap.iterator())
//for (p in Reg.state.playermap.iterator())
for (p in Reg.playermap.iterator())
{
p.guns_arr = [];
NWeapon.setUpWeapons(p);
Expand Down
Loading

0 comments on commit d8dfacf

Please sign in to comment.