NSClassFromString custom class for cocos2dx - cocos2d-iphone

I have 50 more classes to load at runtime. I know the class name as string.
I need to load all the classes from string name. like NSClassFromString, custom class of NSClassFromString for cocos2dx

Don't think it is possible, as methods like NSClassFromString requires reflection. If you wanna just configure what objects do you want to create on this launch, you can create some object that will create needed objects for given string keys(class names in your case).

Related

Spawn Blueprint Class with input parameters C++

I am fairly new to UE4 development so apologies if I am missing something obvious.
I am trying to convert a system from blueprints to C++. In an attempt to convert the SpawnActor node, I found that I am unable to provide input parameters like in the image below where ‘Index’ is a custom input.
In other places, to resolve this issue, I have used BeginDeferredActorSpawnFromClass, used an initialise function to provide parameters, then call FinishSpawningActor. This has worked where I am calling a C++ class.
In this case however, the actor I want to spawn is a blueprint class which is a child based on a C++ class. I am unable to implement BeginDeferredActorSpawnFromClass for this, and therefore am not sure how to pass my parameter to this.
For extra context, in the project there can be multiple characters spawned in the world. I want to pass the index of the character in order to set the material colour of each individual character using the nodes shown below.
I am able to achieve this by spawning the BP character using:
Character = GetWorld()->SpawnActor(...)
Character->Index = Index
And then using EventTick instead of EventBeginPlay but feel this is a bad solution. I would appreciate if someone could advise how to initialise the spawned actor with the required parameter.
Thanks in advance.
I was being stupid. SpawnActorDeferred is the function which serves the purpose required.

Is there any way to define methods for data model when using FMPP?

I want to add methods to my datamodel so I need a way to specify them inside my tdd data file(s).
For example having a tdd data file containing two scalars :
a: 1
b: 1
I would like to add a method area which multiplies them.
Is this even possible and if so how do I achieve this?
So let's say you have MyUtils that has a foo() and a bar() methods, and you want to access those in the templates.
You can add an arbitrary Java objects to the model using the eval data loader in data, like myUtils: eval('new com.example.MyUtils()'). Then you can issue myUtils.foo() in the templates. But, you wanted to add the methods at top level. That's also possible. Both in eval and in a custom DataLoader (whichever you want to use) you have access to engine, the fmpp.Engine object. And then you can pull this trick:
// Note: In case you are using eval, use Java 1.2 syntax (no generics).
TemplateHashModel myUtilsModel = (TemplateHashModel) engine.wrap(new MyUtils());
Map<String, TemplateModel> myUtilsMethodModels = new HashMap<>();
myUtilsMethodModels.put("foo", myUtilsModel.get("foo"));
myUtilsMethodModels.put("bar", myUtilsModel.get("bar"));
return myUtilsMethodModels;
Then you add that Map to data without a name. (If you add a Map to data without a name, its keys become top-level variables.)
Certainly it can be polished to be nicer, like find methods you want automatically, etc. Plus I did not try this above (so typos are possible). But this is the basic idea. (I guess it would be practical if FMPP had a data loader that loads the static methods of a class... But, right now it doesn't have that.)

Generic map objects

I am trying to create an Asset Manager (Much like the one that is provided in the Libgdx library) for SFML in C++. But I am running into the age old problem of templates being one of the worst parts of C++.
I am trying to have a map object hold generic types, the key would be a simple string and the data would be any type I want it to be. Note, I don't want to template the map object to simply hold one generic type throughout the entire map (IE, the map being <string, int>). I want to have different types in the same map so I can load many different assets.
Is there any way I can do something like this?
Thank you for your help and consideration, any little tip goes a long way.
I reiterate my comment about a redesign using a map of manager instead.
Then you could have e.g.
class basic_asset_manager { ... };
class image_asset_manager : public basic_asset_manager { ... };
...
std::unordered_map<std::string, basic_asset_manager*> asset_managers;
asset_managers["image"] = new image_asset_manager;
...
// Load an image from a file
asset_managers["image"]->load("some alias for image", "/some/file/name");
...
// Get image
image = asset_manager["image"]->get("some alias for image");
Maybe not exactly like this, but you hopefully get the point.
You could define a struct or in some cases possibly use a union to pass as the second parameter of the map. Might not be the most elegant solution, but can get the job done.

Why do we need to create an instance of a CFC?

I'm using the CreateObject() method to create an instance of a CFC and then interacting with this newly created 'instance'. I'm doing this because that's how it seems to be done, but I don't understand why we do this.
Why can't we just interact with the CFC directly instead of creating an instance of it?
A CFC is just a file with some code in it, so it makes little sense to suggest "interacting" with it, just the same as you might suggest "interacting" with a CFM file without <cfinclude>-ing it or similar.
A CFC defines a component, and to use a component, one creates an instance of it. In some languages - eg Java - one can have static properties and methods, and one can access them via the class rather than necessarily object, but CFML does not have this concept. CFCs define components which are used as objects, just the same as in other languages a class defines what it is to be an object, and to use an object, one first needs to create an instance of it.
You can call the cfc directly using cfinvoke. You just have to realize that cfinvoke creates an object of the cfc first, then executes the method you invoked. Also, once the method is invoked, the object is no longer available.
If your .cfm page is only going to use one method of the component, cfinvoke is ok because there is less code for you to write. However, if you use two or more, it's less efficient because a new object has to be created each time.
In other word, while you don't have to create an instance of the cfc first, it's often a good idea to do so.
I hope you have read OOPs and its practices. CFC is your 'blueprint' (say a car design) and object is your own data model (say a car of blue color (method to set color), with nitrogen filled tires (method to set pressure in tires) and runs on LPG (method for fuel type)). CF allow you interact directly with CFC (CFINVOKE) and you do not have to create an instance each time but it just only make sense that you would not want to go to workshop/design lab each time you want to change a configuration for your car.

How can I associate data - a string, integer or enum member - with a Gtk::ComboBoxText item?

I am using gktmm 3.0 on an Ubuntu 12.04 box with the default GCC toolchain.
In the C# world, the ComboBox class has a ComboxBox.item[n].value property, which allows you to associate each item in the comboBox with data.
I am looking for something similar in the Gtk::ComboBoxTextclass. How can I associate data - a string, integer or enum member for example - with a particular Gtk::ComboBoxTextitem?
I know that many frameworks provide a genericdata pointer on widgets for such use, as this is quite a common need.
Is there something in Gtk::ComboBoxText class or one of its parent classes that might allow me accomplish this, or do I need to set up such an association myself, using a map or other associative collection?
The Gtk::ComboBoxText append, insert() and prepend() methods allows you to specify an ID string as well as the human-visible text. For instance:
https://developer.gnome.org/gtkmm/stable/classGtk_1_1ComboBoxText.html#a19e80f4e451e23d2c00d3fb11023f9f2
But it would be clearer and more type-safe to use Gtk::ComboBox and define an actual underlying model that contains the associated data. This example uses an int, but you could use other types or use more columns:
https://developer.gnome.org/gtkmm-tutorial/stable/combobox-example-full.html.en