Join us on Discord!
You can help CodeWalrus stay online by donating here.
Menu

Show posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.

Show posts Menu

Messages - Scipi

#16
It wasn't for a serious program, but i had some really weird C code written for the old code golf competitions.

Back in the Game Of Life one, I decided I would write my entry for the GBA. Normally in the GoL, you'd have to implement a swap buffer. The front buffer would hold the previous GoL state while the program used it to build the next state in the back buffer. Then at the end of the frame, the buffers would be flipped and the new front buffer copied to the screen. This all ends up being a good chunk of code. And for Code Golf, that's obviously bad.

However, the GBA has a screen mode which splits video memory into two segments. On any one frame, one segment would be used for drawing the next frame while the other segment is displayed... Sound familiar? So in my GoL entry, I [ab]used video memory to serve as my GoL buffer. I read directly from pixels on the screen for my previous GoL state and read directly to the video backbuffer to generate my next state. Than I simply swap the buffers to increment the GoL sim and to display all in one.

Another weird thing I did was in a previous Code Golf where you had to read your own source file. As part of the program, I needed a concise way to check if I hit the end of the file. Normally, you'd do a comparrison against EOF like so:

i = getc(f);
while(i != EOF){
  //...
  i = getc(f);
}


This is waaay too verbose, though. For starters you have to duplicate i = getc(f);!
You can cut it down if you remember that in C, assignments have an implicit return value (so you can do things like a = b = c)
This turned the code into:

while((i = getc(f)) != EOF)
//...


Pretty good, right? But still not enough. Precedence rules make it so you have to waste two characters on parenthesis. I also wanted to get rid of the EOF comparison wholesale.
In the C standard, EOF is always -1. So by that, you can always add one to get 0, which is the value for false in C. Unfortunately, because we're changing every character that gets read, we have to revert it when we want to use it.

while(i = getc(f)+1) a[i-1]++;

However, this is still an extra 4 characters. I wanted to cut that down even further. It just so happens that -1 is 0xFFFFFFFF. Or all 1's in binary. So all I really needed to do was flip all bits and if the value was -1, it'll become 0. Fortunately, C has a bitwise operator for that: ~. So my final code became:

while(i=~getc(f))a[~i]++;
#17
PC, Mac & Vintage Computers / Re: Simple graphics in
October 22, 2016, 12:27:17 AM
Quote from: c4ooo on October 21, 2016, 10:48:56 PM
Quoteimport java.awt.*;
import java.awt.image.*;
import javax.imageio.*;
import java.lang.*;
import java.io.*;
import javax.swing.*;
Never import entire APIs O.O

That really shouldn't be a big issue. I'd expect the Java linker to be smart enough to only take the classes it needs from the API. It might only slow down compiling to bytecode, at worst.
#18
Quote from: c4ooo on October 17, 2016, 01:20:02 AM
For the past couple of days i have been working on a tilemapper as well as pixel art that will likely be used in walriimon aka walrusRPG :)

You mean PocketWalrus. Walriimon uses Tiled :P

This looks pretty nice so far. A feature to suggest (and isn't hard to implement) is to have Z-order rules for different terrain types. This would be increadibly useful for, say, certain types of tile transitions where you layer transitional tiles ontop one another.

For instance:
->

http://www.gamedev.net/page/resources/_/technical/game-programming/tilemap-based-game-techniques-handling-terrai-r934
#19
PC, Mac & Vintage Computers / Re: Simple graphics in
October 18, 2016, 05:10:05 PM
Quote from: Snektron on October 18, 2016, 08:33:50 AM
I dont recommend using awt for anythkng serious. If you want to make a game in java you shoulf use either lwjgl (or jogl) directly or libGDX if you want helper functions. AWT is really slow.

I second this. Learning awt and such isn't useful if you're going to eventually just use an external library anyways. Also, taking a look at libGDX it gives you a lot of neat features. Tiled support is also a major plus.
#20
General Music Talk / Re: What are you listening to?
October 16, 2016, 04:26:49 PM
#21
Media Talk / Re: Favourite webcomics
October 16, 2016, 04:22:34 PM
I regularly read XKCD.
I used to read Something Of That Ilk, Pokemon Hardmode, and Space Cat back when they were still active.
I really need to catch up on Making A Cat Cry (it's too sad, though)

Oh, and I also read Ogla-aah, maybe I shouldn't share that one :P
#22
Site Discussion & Bug Reports / Re: Map of CW members
October 14, 2016, 02:03:00 AM
Quote from: Dudeman313 on October 14, 2016, 01:36:40 AM
This is real neat, but may I suggest political boundaries? I wish I knew where that orange bar was, because I live in Horseheads, NY and would love to meet up with some CW members.

I'm not from there, but I have a good friend from Maryland named Joe who always talks about Horseheads :D
#23
Site Discussion & Bug Reports / Re: Map of CW members
October 11, 2016, 09:06:11 PM
Huh, looks like there's a small concentration of members with me here in Miami. :)
#24
Other / Re: How good is your French?
September 03, 2016, 04:01:52 PM
QuoteYour Score: 65%
Comme ci comme ça
Your French is so-so. You might be able to get around in France with a little help here and there.

Yeah. Right. :P
#25
Randomness / Re: SXZvYWgncyBBUkc=
August 23, 2016, 01:47:27 AM
VGxSWlowNXRVV2RPZWxGblRtMUpaMDVxU1dkTmVrbG5Ua2RGWjA1RVdXZE9ha2xuVGtSVlowNVhSV2RPYWtWblRsUkpaMDE2U1dkT2FtZG5UbnBCWjA1VVdXZE9iVVZuVGtSWlowNVVXUQ
#26
Other / Re: I can give you a cheap vintage computer
July 11, 2016, 01:18:02 AM
If you can ship to Miami, Florida and are able to withhold one for a few weeks until I get a place established, I'd gladly buy one of those off of you.
#27
Quote from: Cumred_Snektron on May 05, 2016, 05:31:47 PM
You had a cool idea and are searching for a way to show it off? :P
Though it is a cool idea

Unfortunately, I don't. XD I just want an excuse to make one and stay committed to it. ;)
#28
I've always wanted to do a contest or jam where participants make a programming game like Core Wars or TIS-100.
#29
I'm partial to the WTFPL license.
#30


And don't worry, this is a parody of Trump more than anything. I'm basically saying he's a reptilian shapeshifter out to usurp our government. :P
Powered by EzPortal