Friday, August 17, 2012

Java:Trials and Tribulations of staying organized and responsibility

So, I started going back to java for a few reasons
1) Java Games are becoming mainstream again (i.e Minecraft)
2) I can mod games
3) For android applications

However, as my first projects I took up a bunch of simple games
http://www.cokeandcode.com/
Provides a lot of nice tutorials, likewise so did
http://www.javacooperation.gmxhome.de/Applets/Games/JrioGame/JrioEng.html

A common thing I noticed between these two tutorials was that I had to hand code the games myself.
This wasn't that big of a deal to me though since thats something I inspire to create: ground up frameworks

So, I started out trying to do Proof of concept for a few things
1) since java would send entire objects into functions, I made sure that each of my rendering engines only took an array of semantic data
for example: Graphic Handler took a int[][][]
first array was for layers
second was for images in that layer
third was semantic data
1: image reference
2: image animation reference (I would breakup a single image into parts)
3: x position
4: y position

2) Seperate my rendering method from my game
This means that I would seperate the game as much as possible from "frames" or "Applet" code allowing my game to specifically focus on what its suppose to do rather than have to rewrite my rendering engine just so that i can export it

Now this was successful, and I was able to prove it worked by adding a simple game (hardcoded) into the game loop and play with it
Now, that was all fine and dandy
But I desipise single player games generally
-not because they aren't fun, but because I'm competitive at heart

Likewise I don't like using keyboard and mouse so....
Jinput - http://java.net/projects/jinput/
What Jinput allows me to do is see all of the connected hardware and buttons on my computer and allow me to set them as my game buttons.
Now... thats cool in my opinon...

But before I do that, I wanted to set it up so I can make it multiplayer....

Thats where things started going downhill

I added two new classes
LogicHandler Class
PlayerHandler Class

The point of Logic Handler was to be the game
-Graphics were just graphics
-Sound would be thread seperated
-Player inputs are also thread seperated
-Logic is the game.

GameLoopRun(){
LogicHandler.doLogic(PlayerHandler.getInputs);
//this would send a hasmap of the players current inputs (which would be an array)
//and make the logic handler do appropiate playe rmovements, then hitdetection, then etc
GraphicHandler.prepareGraphics(LogicHandler.getGraphicData());
AudioHandler.prepareAudio(LogicHandler.getAudioData());
//Prepares all the audio and graphic data based on arrays sent from logichandler
Sleep(previoustime+timetowait - currenttime);
GraphicHandler.fire();
AudioHandler.fire();
//this would do the actions
}

However....
I've hardcoded my proof of concept so much that when I took one thing out another broke
And so many errors I would have to sort through

On top of that (because again... everything is so hardcoded) I realized if I wanted to make the games built of a series XML files and associated pictures and sounds (which was the plan) I would have to redo my rendering engine as well to make sure that Strings and Containers would be dealt with appropiately

I don't want to use Swing... I don't... honestly...
but the fact of the matter is, my small little plan was turning into a grand scheme that I don't think I would be able to handle

This was my Plan

Platform - Variable Class that I would be able to switch in and switch out as my desire.
-Important ones were; JFrame, fullscreen (very important since there will be less operating system intereference), Applet, and jnlp (which i think is just jframe with a semantic xml file from the research i did)


GameLoop
-The thread that would have the highest priority. I needed to make sure the gameloop would run, everyother thread will have to sit on the wayside and hope they get their turn

Player Handler
-lagRespect function-would respect the lag of the webplayers and force your button inputs to be delayed as well. also would need to get a once in a while position update. would also send controller inputs to web servers

-Player
--ID to be sorted and looked for
--List of inputs and their current state
---set inputs function

-WebHandler
--The amount of lag
--List of IP to ID
--get playerlist from server x (would return a list of players, their IP addresses and server port)
--Personal Server
---Open/Close for new players from the web

---poll function that is basically a thread that accepts each client socket inputs and set them to the appropiate player


-Controller Handler
--List of Controller to ID
--poll function that would poll only the important controllers and set the player to the appropiate state


Graphic Handler
-Needs to preload all images before hand
-Data it would accept
--String, Color, xpos, ypos
--width, height, Color (as hex), xpos, ypos
--Picture, Animation(single picture is cutup into peices), xpos, ypos
-buffers it
-displays it

Audio Handler
-Data it would accept was something I was still confused about since I wanted it to be pretty advanced yet intuitive was left with
--Sound number, start or stop
-Honestly, Audio simple was enough of a hassle to start, though I wouldn't be satisfied until I could do modulation and such

Logic Hander
-Player inputs to Logic Changing
-Velocity try
--foreach(blockwidth/height change)Hit Detect
-Change State


Regardless
I got disorganized in my code
And everything started falling apart
I eventually tried to go back and make things work one by one
Then I realized I didn't save old copies
There were so many changes...
I need to take a break from this project I believe

Thursday, August 9, 2012

jQuery: Such a cute little Language

I've been avoiding jQuery for a long time for the simple fact I'd prefer doing things on my own.
I've built my own fades and animations with timeout
I've built my own ajax systems, websites, etc

But I must say, after using jQuery, I'll say its absolutely adorable!

Selectors....

Are Damn Sexy
CSS does do a great job searching through a document and making the changes needed
#bodywrap{width:900px;margin:auto;}
.itemheader{line-height:20px;}
li{display:inline-block;}
Its fluid, its simple, its modular
I'm better off making class and id names but I don't even need to. I could also use :first, :nth-child, [attr=x]
and the fact
An excellent article about it


the Stack

If your familiar with magic the gathering, this would make sense to you. If else, I'll try my best
jQuery is severly stackbased
doing...
jQuery('#love').fadeTo(500, .5).css('position', 'relative').animate({'left':200, 'top':200}, 1000).fadeTo(500, 1).animate({'left':0, 'top':0}, 1000).css('position', 'static');
will do that in order.
cute and simple

I'm going to start screqing around with putting things on top and bottom of stack as well as pausing and unpausing animation but so far it involves a bit more in depth look.
I'm alright with that, depth is nice sometimes

Another nice thing is seperate animations hapen seperately. nifty and nice

Wednesday, August 8, 2012

Wordpress: I just want your -Admin inter- face


So...
I was writing a java gamefor about 2 weeks before a freind of mine called me up and gave me some details of website work. Now, I like money, and I also like programming. And with my previous experiences with wordpress and etc I figured not that big of a deal.

However, I've never gone that in depth into wordpess, always finding workarounds and essentially using php with wordpress and a derp admin system.
Since I've been working so hard on my java stuff I figured I'd learn the codex and actually use wordpress properly.

Little did I realize that Javas documentation and uses are far more my style than wordpresses. I'm used to going in depth, barebones and figuring out things for myself. Java is nice because I can create my abstract class then base everything off from there. Seperate any rendering that I need to get done either into its own class or individualized.
Lists of data I'm comfortable with, wordpress style doesn't feel righte

In wordpress its a different.
1) Register Post Type
-register Post type isn't really about creating an object at all, its more about what it will be named and how admins will deal with it. On top of your selection of micky D meals (premade aspects that are useful and saves you time) when it comes to meta boxes are quite limited.

But I severely question the design concept to make sure people had extrodinair customization of labeling and visibility yet limited content.

Now, I feel that this sin't 100% a bad decision and in fact gives us as developers the drive and desire to be creative. The idea is "Hey We'll only give you our Core. But You can add in Yours!"

2) add_meta_box
So.... This is it?
Fyi, these are all semantic details and call back html.
Meaning.... even though I just added a meta box, it inheritly does nothing except exsists....

But thats cool when it comes to objects. I understand that... You start off with an abstract and you turn it into an object.
And for what its worth, I was able to just turn a function into an abstract for the rest of my post types. No big deal.
But It was kind of Disturbing how I had to add in my data. not because its difficult, but because I felt as though it would have been easier to do it through he core of php than use wordpress...

3) Metabox HTML

now, I feel the nonce could be created itself by just simply doing it without my need to add it.
And for what its worth, I don't feel intergrated into wordpress. I may be, but its just html... Nothing fancy, no jquery aspects, just html.
But thats fine, it allows me to do customization...
4) Saving the Return
And finally... I save.
I save post variables. I have post, i have post_id
but for what its worth I don't think its necessarilly appropiate for a proper CMS
theres room for human error when it comes to efficiency and security. While if they forced each metabox to be saved through their system they can set them to IDs making each aspect much more semantic rather efficient than giving the oppertunity for a plugin creator to mess up (Myself included).


Conclusion

In general, I enjoy the interface but when it comes down to it, I'm not really getting in it, I'm simply asking for a box. A box to put in html that I'm forced to customize myself using javascript footer hooks and css header hooks. Making a saving feature that shouldn't even need to be done by me for the mere fact that the need to make sure their system is secure. If I don't create the nonces or make sure that people with capabilities aren't editing it, would my system be secure? if I make a loop and allow any div with mozoData inside, would script kitties try to create their own random inputs with names associated with mozo? shouldI really be in control over ids of the wp_admin screen? should I? I think not. for the simple reason they need to make sure each ID is alone. no multiples. period. meta boxes should be objects in themselves. I should be able to create my own meta box just like I would create a new post type,

In general, the system isn't really secure, its not very object oriented and its hardly integrated into the core
Nonetheless, its modular, pretty and works
And when it comes down to it, if I have something that is modular, pretty and works. I'm pretty happy.