lunes, 24 de marzo de 2014

Packt Publishing 2000th Title Celebration Offer

As part of the Packt's release of its 20000th Title I wanted to inform my readers that there is an exciting offer Packt is running. Basically you buy any book and get another one for free! 

The campaign began on 18th-Mar-2014 and will continue up until 26th-Mar-2014. Following are the benefits readers can avail during this campaign.
  •     Unlimited purchases during the offer period
  •     Offer is automatically applied at checkout

For more information:

jueves, 19 de diciembre de 2013

Mobile Game Design Essentials (Book Review)

I am honored to be selected as reviewer of Mobile Game Design Essentials book by Dr. Claudio Scolastici and David Nolte (Packt Publishing).

So far I think the book is accomplishing its goal. The target audience could range from entrepreneurs wishing to start a mobile games development team to a solo mobile developer wanting to know more about the actual business and possibly form a team.


Chapter 1 - Operating Systems - Mobile and Otherwise
The book starts with the different operating systems in the mobile space providing detailed information about development systems, IDE, the language needed (Java for Android, Obj-C for iOS, etc) and a simple explanation of each application store. Not meant to be a deep explanation but an overview of the multiple options in mobile space.

Chapter 2 - The Mobile Indie Team
This chapter is about what professionals are needed for setting up a mobile team. This is a very basic and informative chapter about human resources and skills. It includes references to famous schools and others if you wish to follow a certain path for an eventual mobile games industry insertion.

Chapter 3 - Graphics for Mobile
This chapter comprises a detailed explanation of the different graphic assets used in games in general (not only mobile). It includes 2D and 3D assets (sprites, textures, models, etc) and a good reference about the user interface and HUD.  

Chapter 4 - Audio For Mobile
This chapter describes audio compression formats, common concepts and definitions, audio tools and edition. The really valuable section of this chapter is the audio design on mobile specifically, which may help you a lot while developing mobile games.

Chapter 5 - Coding Games
In this chapter the authors describe what programming languages are generally used for mobile development as well as a very basic overview of memory management, programming concepts and recent technologies such as HTML5 for game development. If you are a decent developer this chapter would seem too basic. For a non programmer however, this will represent valuable information to understand what's possible and what is not.

Chapter 6 - Mobile Game Controls
This chapter presents a detailed summary of the various forms of user input supported by mobile devices as well as the general definitions for bleeding-edge technologies such as eye tracking and brainwave readers. Very interesting read since it discusses all you need to know when designing a game that could exploit all possible user input.

Chapter 7 - Interface Design for Mobile Games
This chapter discusses the traditional UI design concepts and how they are adapted for mobile development. It includes a set of best practices to create an effective mobile UI.

Chapter 8 -  Mobile Game Engines
This chapter is more of a reference to available game engines specially targeted at mobile. A detailed description is offered for every game engine with its pros and cons. A simple Unity3d setup sample is available.

Chapter 9 - Prototyping
In this chapter the authors take us through the definition and execution of prototyping a mobile application. This does not only apply to mobile though. It comprises an excellent summary of how to implement a successful prototype and the tools that can help in the process. It includes a unity3d scene sample (with some scripting) to illustrate the point of prototyping.  

Chapter 10 - Balancing, Tuning, and Polishing Mobile Games
In my opinion this is the best chapter of the entire book. It gives us a detailed definition of common game parameters like balancing, symmetry, randomization, feedback loops, statistics, AI, etc. After that the authors explain tuning strategies and difficulty settings. They illustrate their points with a Unity3D game sample evidencing all the theory.

Chapter 11 - Mobile Game Design
This chapter illustrates the fundamental concepts in mobile game design taking into account all that has been learned up to this point in the book. It discusses design as a global strategy and present best practices to adapt the process. The most interesting section is how to provide fun games (heavily supported by the fun game theory).

Chapter 12 - Pitching a Mobile Game
In this chapter the authors present a pitching template so you can reuse it to get funding of your game by presenting it to potential publishers. It clearly explains all the details that need to be included in this document.

-------------------------------------------------------

This book is an excellent read for those wishing to start mobile development (games) and have no knowledge about what is involved. In my opinion the authors made a good job summarizing every concept and bringing them together. Excellent reference book.

Thanks,

miércoles, 18 de diciembre de 2013

Ehcache Cache Search API Fundamentals

Introduction

In this entry I want to give out an excerpt of my book Instant Effective Caching with Ehcache. I have chosen the Ehcache Search API chapter so we can analyze a very simple example about its internals and a practical implementation. If you would like to purchase a copy of the book please follow the links:

Amazon:
http://www.amazon.com/Instant-Effective-Caching-Ehcache-Daniel/

PacktPub:
http://www.packtpub.com/effective-caching-with-ehcache/book


Getting Ready

EhCache search API allows us to query and search for elements that are already cached. This is achieved thanks to the ability to use indexing on keys and/or values pertaining to the object being cached. Ehcache provides queries that let us create arbitrary complex searches based on conditions, making this tool indispensable for professional caching.

To get the most of this tutorial download this book's recipe source code from github (or optionally clone the repository to get all the book's recipes source code) here:

https://github.com/danielwind/EhCache-Effective-Caching/tree/master/Recipe%206


How to do it

I will assume that you are using Maven to build your Java Project. If this is not the case, then you just need to make sure you are linking the following library jars in your project:

Step 1: Add Ehcache and SLF4j dependencies in your POM.xml

<dependency>

 <groupid>org.slf4j</groupid>

   <artifactid>slf4j-log4j12</artifactid>

 <version>1.7.2</version>

</dependency>

<dependency>

   <groupid>net.sf.ehcache</groupid>

   <artifactid>ehcache</artifactid>

   <version>2.6.0</version>

   <type>pom</type>

</dependency>


Step 2: Add to your ehcache.xml the searchable tag (to enable search) and search attributes to map your POJO getters:

<cache name="employeeCache" maxElementsInMemory="100" eternal="true" overflowToDisk="false">

   ...


   <!-- Adding Ehcache searchable capabilities -->

   <searchable>

       <searchAttribute name="firstname" expression="value.getFirstName()"/>

       <searchAttribute name="profile" expression="value.getProfile()"/>      
       
       <searchAttribute name="social" expression="value.getSocialNumber()"/>
       
       <!-- Profile Children Nodes -->
       <searchAttribute name="department" 
                       expression="value.getProfile().getDepartment()"/>
       
       <searchAttribute name="role" 
                       expression="value.getProfile().getRole()"/>
     
       <searchAttribute name="salary"
                      expression="value.getProfile().getSalary()"/>
       
       <!-- Adding a custom attribute extractor for performance reason -->
       <searchAttribute name="lastname"
                        class="com.foo.cache.LastNameAttributeExtractor"/>
   </searchable>


</cache>



Step 3: Create a Map to hold references to the search attributes defined previously in step 2:

 /**
 * load the attributes (as defined in ehcache.xml)
 * and store them in the reusable Cache Attributes Map
 **/   

HashMap> cacheAttributes = new HashMap>();

cacheAttributes.put("lastname", cache.getSearchAttribute("lastname"));
cacheAttributes.put("profile", cache.getSearchAttribute("profile"));
cacheAttributes.put("department", cache.getSearchAttribute("department"));
cacheAttributes.put("role", cache.getSearchAttribute("role"));
cacheAttributes.put("salary", cache.getSearchAttribute("salary"));
cacheAttributes.put("social", cache.getSearchAttribute("social")); 


Step 4: (Optional) Create an Attribute Extractor to improve performance:

...
import net.sf.ehcache.search.attribute.AttributeExtractor;
import net.sf.ehcache.search.attribute.AttributeExtractorException;

public final class LastNameAttributeExtractor implements AttributeExtractor {

 private static final long serialVersionUID = 1L;

 public Object attributeFor(Element element) throws AttributeExtractorException {

  return attributeFor(element);
 }

 public Object attributeFor(Element element, String attributeName) {

  return ((YourPojo) element.getValue()).getLastName();
 }

} 


Step 5: Implement a method that uses Ehcache Search API:

public List searchEngineers() {

 log.info("Searching all employees whose role is: " + Role.ENGINEER);

 List employees = new ArrayList();

 //create Ehcache Search API Query
 Query query = cache.createQuery();

 //cast attribute from HashMap
 Attribute attribute = (Attribute) cacheAttributes.get("role");

 //add query criteria like: 'select {key, value} from Employee where role = ${@param role}'
 query.addCriteria(attribute.eq(Role.ENGINEER));

 //get the results list and loop on them
 Results results = query.execute();

 for(Result result : results.all()){
  
  log.info("Key: " + result.getKey());
  log.info("Value: " + result.getValue());
  log.info("Value Class: " + result.getValue().getClass());

  Employee employee = (Employee) result.getValue();
  employees.add(employee);
 }

 return employees;
}  


How It Works

Ehcache provides a simple to use Search API that allows us to retrieve objects from cache layer based on conditions and other criteria. The implementation resembles that one of simple JDBC – SQL queries.

  1. We start by editing the Ehcache configuration by adding the searchable directive. This tells Ehcache that for that particular cache we want it to be searchable.

  2. We then define the Search Attributes. These are index mappings that tell Ehcache what attribute of your object you want to be searchable and a name to refer to it (always use “value” as your object reference).

  3. Now, in our code we need to create a map to hold attributes (not strictly necessary but a good practice and convenient way to access the attributes in an ordered way).

  4.  Finally we create methods (at your convenience) that hold the search queries logic.


Optionally, if your cache object layer is complex, you will want to implement a custom accessor that can help you to increase performance while lookups. This can be easily achieved by implementing the Ehcache AttributeExtractor interface and redefining the behavior you desire. The procedure is just like if you were defining an index in a SQL table.

You can find a fully working sample project in my github repository (please refer to the top of this entry for details on how to get it).

Thanks,