forked from ZaneDubya/YCPU
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
125 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
using System.Text; | ||
|
||
namespace Ypsilon.Core { | ||
public static class Strings { | ||
public static readonly char Delim = '|'; | ||
public static string Name = "PlayerName"; | ||
|
||
public static string Localize(string s) { | ||
StringBuilder sb = new StringBuilder(s); | ||
sb.Replace("%name%", Name); | ||
return sb.ToString(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
using Ypsilon.Core.Input; | ||
using Ypsilon.Core.Patterns.MVC; | ||
|
||
namespace Ypsilon.Core { | ||
public class ModeManager { | ||
private AModel m_Model; | ||
private AModel m_QueuedModel; | ||
|
||
public AModel ActiveModel { | ||
get { return m_Model; } | ||
set { | ||
if (m_Model != null) { | ||
m_Model.Dispose(); | ||
m_Model = null; | ||
} | ||
m_Model = value; | ||
m_Model?.Initialize(); | ||
} | ||
} | ||
|
||
public AModel QueuedModel { | ||
get { return m_QueuedModel; } | ||
set { | ||
if (m_QueuedModel != null) { | ||
m_QueuedModel.Dispose(); | ||
m_QueuedModel = null; | ||
} | ||
m_QueuedModel = value; | ||
m_QueuedModel?.Initialize(); | ||
} | ||
} | ||
|
||
public void ActivateQueuedModel() { | ||
if (m_QueuedModel != null) { | ||
ActiveModel = QueuedModel; | ||
m_QueuedModel = null; | ||
} | ||
} | ||
|
||
public void Draw(float frameSeconds) { | ||
m_Model.GetView().Draw(frameSeconds); | ||
} | ||
|
||
public void Update(float totalSeconds, float frameSeconds) { | ||
if (m_QueuedModel != null) { | ||
ActivateQueuedModel(); | ||
} | ||
InputManager input = ServiceRegistry.GetService<InputManager>(); | ||
m_Model.Update(totalSeconds, frameSeconds); | ||
m_Model.GetController().Update(frameSeconds, input); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
|
||
namespace Ypsilon.Core { | ||
public static class ServiceRegistry { | ||
private static readonly Dictionary<Type, object> m_Services = new Dictionary<Type, object>(); | ||
|
||
public static T GetService<T>() { | ||
Type type = typeof(T); | ||
if (m_Services.ContainsKey(type)) { | ||
return (T)m_Services[type]; | ||
} | ||
else { | ||
// Tracer.Critical(string.Format("Attempted to get service service of type {0}, but no service of this type is registered.", type.ToString())); | ||
return default(T); | ||
} | ||
} | ||
|
||
public static T Register<T>(T service) { | ||
Type type = typeof(T); | ||
if (m_Services.ContainsKey(type)) { | ||
// Tracer.Critical(string.Format("Attempted to register service of type {0} twice.", type.ToString())); | ||
m_Services.Remove(type); | ||
} | ||
m_Services.Add(type, service); | ||
return service; | ||
} | ||
|
||
public static bool ServiceExists<T>() { | ||
Type type = typeof(T); | ||
if (m_Services.ContainsKey(type)) { | ||
return true; | ||
} | ||
else { | ||
return false; | ||
} | ||
} | ||
|
||
public static void Unregister<T>() { | ||
Type type = typeof(T); | ||
if (m_Services.ContainsKey(type)) { | ||
m_Services.Remove(type); | ||
} | ||
else { | ||
// Tracer.Critical(string.Format("Attempted to unregister service of type {0}, but no service of this type (or type and equality) is registered.", type.ToString())); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters