How to fix Error Has no member "create" - cocos2d-x

bool AppDelegate::applicationDidFinishLaunching() {
auto director = Director::getInstance();
auto glview = director->getOpenGLView();
if(!glview) {
glview = GLView::create("My Game");
director->setOpenGLView(glview);
}
i don't know why my code has this problem 4 IntelliSense: class "cocos2d::GLView" has no member "create". Iam building for windows 32bit.

GLView is an abstract base class that is shared by all platforms.
The implementation class is typically called GLViewImpl, but its creation function is still platform specific. So, on iOS, you need to call GLViewImpl::createWithEAGLView.

As Chris mentioned GLView is an abstract class. If you're running on Win32 then you should use:
GLViewImpl::createWithRect("Window name", Rect(0, 0, designResolutionSize.width, designResolutionSize.height));
Let me know if this helps.

Related

How to only use IOC container from MVVMCross

I'm working on a existing Windows Phone project and want to use the IOC container from MVVMCross, but not the other extra features (yet).
I installed MVVMCross.Core 4.x and try to use 'ConstructAndRegisterSingleton' from the App() constructor of the Windows app, but it throws an Null ref exception.
Tried to find any bootstrapper, setup or initialization for MVVMCross but can't find any in the new 4.x core.
Anyone any idea?
Found it.... and it seems to work.
Just get MVVMCross.Core from Nuget and create a setup like:
internal static class Setup
{
public static void InitializeIoc()
{
CreateIocProvider();
// Register all services
Mvx.ConstructAndRegisterSingleton<ILoudnessLimitsRegulator, LoudnessLimitsRegulator>();
}
private static void CreateIocProvider()
{
// Ioc options
var options = new MvxIocOptions();
// initialize the IoC registry, then add it to itself
var iocProvider = MvxSimpleIoCContainer.Initialize(options);
Mvx.RegisterSingleton(iocProvider);
}
}

How to declare static field in class

I have a XAML + DirectX app and I want to add static field to my "interop" class:
[Windows::Foundation::Metadata::WebHostHidden]
public ref class Direct3DInterop sealed : public Windows::Phone::Input::Interop::IDrawingSurfaceManipulationHandler
{
public:
static int VALUE = 0;
...
};
It does not compile saying "only static const integral data members can be initialized within a class".
If I change it to const static int VALUE = 0; then it still does not compile with error "a non-value type cannot have any public data members"
What am I doing wrong?
WinRT public classes have a number of limitations to ensure they are consumable by multiple languages including C++, JavaScript, and C#. This is why you are getting error C3984. You can't have public fields and instead must use properties. You'd make it a read-only property:
property int VALUE
{
int get() { return 0; }
}
It is important to remember that properties are function calls and can't usually be optimized away, so you should consider that when designing the interfaces.
If you intend to have this class only consumable by C++, consider not using a WinRT class and instead use a simple C++ class which you managed the lifetime using std::unique_ptr or std::shared_ptr. In that case, you can of course use the public field approach as always.
The original problem you got is a general C++ language restriction not specific to WinRT. Error C2864 (you are using VS 2012 from the text you posted) is a little more general with C++11 in VS2013.

Is there a way that i can unregister a module from Jackson ObjectMapper?

I'm registering KeyDeseriliser to ObjectMapper. After reading JSON I want to unregister this module. Because my ObjectMapper is static and I don't want to use this module in any other places.
SimpleModule module = new SimpleModule("EnhancedDatesModule", new Version(0, 1, 0, "test", "Test-id",
"testest"));
module.addKeyDeserializer(EncounterCURN.class, new MapKeyDeseriliser());
objectMapper.registerModule(module);
Map<EncounterCURN, Collection<EncounterTodo>> encounterTodosByEncounter = mapReader.readValue(nodes.get("todos"));
No, you can not do this. You should create another ObjectMapper and use it.
By the way, static fields this is a not a good habit of programming in Java. You should avoid situations like this where such kind of objects are static.
The module has a setSerializers, according to the docs:
/**
* Resets all currently configured serializers.
*/
public void setSerializers(SimpleSerializers s) {
_serializers = s;
}
So, what you can do is call the setter with a new empty SimpleSerializers object.
Disclaimer: I am not 100% sure how this will workout in from a thread-safety point of view.

Register types based on base class

I'm trying to figure out Windsor as an IOC container.
The problem I'm facing right now is to register all of my viewmodels at once.
I've taken a look at the docs and thought that the following code should work.
However, when I check the container afterwards, nothing is registered.
container.Register(Classes.FromThisAssembly()
.BasedOn<ViewModelBase>()
.LifestyleTransient());
where ViewModelBase is my baseclass.
Also tried the following:
container.Register(Classes.FromThisAssembly()
.InSameNamespaceAs<MainWindowViewModel>()
.LifestyleTransient());
The necessary dependencies can be resolved, the viewmodels not.
I suppose I'm missing something obvious here?
Edit
My dependencies are registered as follows:
this.container.Register(Component.For<IDALHandler>().ImplementedBy<DALHandler>());
this.container.Register(Component.For<IBLHandler>().ImplementedBy<BLHandler>());
UPDATE
Since the suggestions didn't work, I was planning on adding the code from my baseclass and viewmodel here.
While doing so I noticed that my viewmodel-class was internal sealed. When changing it to public sealed, the above code did work.
Can someone explain why internal classes can't be registered in the container?
I've already tested other IOC containers with the exact same setup and they didn't complain about it.
Your example of registration started working well in my application when I added selection of the service for component. E.g. .WithService.AllInterfaces()
container.Register(Classes.FromThisAssembly()
.BasedOn(typeof(MyBaseClass<>))
.WithService.AllInterfaces()
.LifestylePerWebRequest()
);
container.Register(Classes.FromThisAssembly()
.InSameNamespaceAs<MyBaseClass>()
.WithService.AllInterfaces()
.LifestylePerWebRequest()
);
UPDATE:
In order to register internal types, .IncludeNonPublicTypes() should be used.
public class ExampleTest
{
[Test]
public void MyBaseClass_Base()
{
var target = new WindsorContainer();
target.Register(Classes.FromThisAssembly()
.IncludeNonPublicTypes()
.BasedOn(typeof(MyBaseClass<>))
.WithService.Base()
//.LifestylePerWebRequest()
);
//assert
target.Resolve<MyBaseClass<int>>().Should().BeOfType<A>();
target.Resolve<MyBaseClass<string>>().Should().BeOfType<B>();
}
[Test]
public void MyBaseClass_Self()
{
var target = new WindsorContainer();
target.Register(Classes.FromThisAssembly()
.IncludeNonPublicTypes()
.BasedOn(typeof(MyBaseClass<>))
.WithService.Self()
//.LifestylePerWebRequest()
);
//assert
target.Resolve<MyBaseClass<int>>().Should().BeOfType<MyBaseClass<int>>();
target.Resolve<MyBaseClass<string>>().Should().BeOfType<MyBaseClass<string>>();
target.Resolve<A>().Should().BeOfType<A>();
target.Resolve<B>().Should().BeOfType<B>();
}
}
internal class MyBaseClass<T>
{
}
internal class A : MyBaseClass<int>
{
}
internal class B : MyBaseClass<string>
{
}
My guess is your viewmodels have been registered in the container, but they are not resolvable through their interface.
Set a breakpoint after the registration and check if container has been filled as expected.
UPDATE as per my comment below:
Keep in mind "group" registration (Classes.) skips internal class.
If they have been registered, let say you have a ViewModel like this
public class MyViewModel1 : ViewModelBase, IMyViewModel1
container.Resolve<MyViewModel1>() // resolve
container.Resolve<IMyViewModel1>() // no resolve
to accomplish the second resolving scenario you have to do what Ilya pointed about about adding WithService during registration, so you can resolve by interface instead of by concrete.

Can anybody explain the concept of pluggable adapter to me with good example?

Can anybody explain the concept of pluggable adapter to me with good example?
From what I understood from a quick reading of Google results, a pluggable adapter is an adapter that isn't hard-coded against a specific adaptee. On the surface (the adapter's own interface), it's all the same but it can adapt to different adaptees with different interfaces. I found this thread pretty explanatory:
Basically, it allows you to put in an
adapter when the adaptee (receiver)
protocol is not known at compile time
by using reflection. When you create
the adapter instance, you pass it the
name of the adaptee's method to call,
and also any metadata that's necessary
to translate input types. When the
adapter receives a method call of the
target interface, it uses reflection
to call the corresponding method
specified on the adaptee.
And this:
The main responsibility of the Viewer
is to populate a widget from a domain
model without making any assumptions
about domain itself. JFace viewer uses
the Delegating Objects mechanism in
Pluggable Adapter Pattern to implement
the above requirement.
Think of it as a facehugger from Alien; when it hugs a face, all you see is the slimy back of the facehugger. You can poke it with a stick and try to pry off its arms (the adapter interface). But it basically can hug the face of any human (the adaptee), regardless of the face features. Maybe I'm pushing it a bit, but, hey, I love Alien.
You can read this article about adapter/pluggable pattern:
Table of content in this article:
* 1 Design Patterns
* 2 Intent of Adapter
* 3 Motivation
* 4 Structure
* 5 Applicability
* 6 Consequences
* 7 Implementation
o 7.1 Known Uses and Sample Code
o 7.2 Related Patterns
* 8 Conclusions
* 9 Appendix
o 9.1 References
o 9.2 Glossary
Quote:
Smalltalk introduced the concept of a
"pluggable adapter" to describe
classes with built-in interface
adaptation. This interesting concept
allows for classes to be introduced
into existing systems that might
expect different interfaces to the
class. This technique can help promote
class reuse across modules and even
projects.
Here is a small example:
We have two classes - Foo & Boo that outputs some string to console. Adapter class can adapt methods from both classes to provide interface (SaySomething) required by client. Note that there is no dependency on interface name - we can easily adapt both SayHey and Bark methods.
class Foo
{
public static void SayHey() { Console.WriteLine("Hey!"); }
}
class Boo
{
public static void Bark() { Console.WriteLine("Woof!"); }
}
class Adapter
{
public Action SaySomething { get; private set;} // "pluggable" adapter
public Adapter(Action saySomethingAction)
{
SaySomething = saySomethingAction;
}
}
class Program
{
static void Main(string[] args)
{
(new Adapter(Foo.SayHey)).SaySomething();
(new Adapter(Boo.Bark)).SaySomething();
}
}
A distinguish Feature of the Pluggable Adapter is that the method called by the client and the method existing in the interface can be different.
interface Ilegacy
{
float calculate(int a, int b);
}
class Legacy : Ilegacy
{
public float calculate(int a, int b)
{
return a * b;
}
}
class Adapter
{
public Func<int, int, float> legacyCalculator;
public Adapter()
{
this.legacyCalculator = new Legacy().calculate;
}
}
class Client
{
static void Main()
{
float result = new Adapter().legacyCalculator(5, 6);
}
}
This can normally acheived with the use of delegate,Func or Action in C#