Compare commits

..

278 Commits

Author SHA1 Message Date
Kayne Ruse 61848db65b Merging branch 'develop' into master (read more)
List of major changes:
* Refactored the server into smaller modules
 * Server now partially supports multiple rooms
* Overhauled the networking code
 * Packets are now a hierarchy of classes
 * Changed the way packets are moved about
 * Initial login protocol altered
* Reworked the map system
 * Two separate pager classes, one with lua one without
 * lua API supports these changes, and partially supports rooms
* Major and minor bugfixes as the need arose

This is the culmination of three weeks of work, but it feels like so much longer. Ideally there shouldn't be any major visible changes to the game, even though the code has undergone a huge revision. The intent of these changes was to make future progress much faster, and I'm not planning on doing this again any time soon. This commit is intened for 'release-0.4.1', whereas 'release-0.4' was only the first half. Naturally when you think something is done, you're only half way there.

My plans are to return to the combat system, and get it working as an actual playable system to show off. Following that, I'll begin researching the terrain generation. I'm estimating that these tasks will take 2 months each, but I'll probably be pouring as much effort into these as I did with this commit. As usual, development is rarely straight forward, so I'll probably get sidetracked at some point (hence the large development window). If I do stick to my timeline, I'll reach a "playable" alpha by mid-october. From there I'll have 2.5 months to flesh out some gameplay, and possibly submit the game to Greenlight.

After working on this game for a year, I wonder how much further there is to go before other people play it.
2014-06-15 00:04:41 +10:00
Kayne Ruse dfc464ddd6 Merge branch 'char-add' into develop, characters working again 2014-06-14 23:30:57 +10:00
Kayne Ruse bd5e57401e Minor comment tweaks 2014-06-14 23:27:33 +10:00
Kayne Ruse a23fbbfb38 Characters are working correctly again 2014-06-14 23:13:11 +10:00
Kayne Ruse c021032512 The character is visible, fixed a database issue 2014-06-14 22:37:21 +10:00
Kayne Ruse d4be22a6eb Merge branch 'develop' into char-add
I just want that minor tweak from master here
2014-06-14 04:14:36 +10:00
Kayne Ruse c210b99a5f Merging a slight change to master 2014-06-14 04:08:18 +10:00
Kayne Ruse 01eb934fad Merge branch 'client-fix' into develop (read more)
Summary of changes:
* Changed the way I handle packets
* RoomManager is now functional
* Split RegionPager into two classes
* Fixed several major and minor bugs
2014-06-14 04:03:55 +10:00
Kayne Ruse 52e6b144c1 Merge branch 'map-redo' into client-fix (read more)
This merge splits RegionPager into two parts: RegionPagerBase, with the
basic Region management code, and RegionPagerLua, which has lua hooks. The
former is used by the client while the latter is used by the server. Both
classes' internals have been optimized.

There are also changes to the client and server code, to account for the
new system, and I've fixed a couple of bugs.

The player's character is not created, but the client can login and see
the map.
2014-06-14 03:46:16 +10:00
Kayne Ruse b418ad713d Worked these changes into the client & server (read more)
The changes were fairly easy, and I was actually able to find and fix an
out-of-sequence bug: The destructors for the AccountManager and the
CharacterManager were using SQL code after the call to SQLite3_close_v2(),
so I added and called UnloadAll() for both of them.
2014-06-14 03:38:13 +10:00
Kayne Ruse 1bc51fe035 Removed the 'erase_if' template, that was silly 2014-06-14 03:08:33 +10:00
Kayne Ruse 793737e1ed Experimenting with the map 2014-06-14 03:05:21 +10:00
Kayne Ruse e57b047343 Added some basic code to RoomManager 2014-06-14 00:44:13 +10:00
Kayne Ruse a11867126c Fixed segfault in common, changed casting of packets to static_cast
This required that I switch from using a char array for the packet buffers
to using malloc() and free(). They make more sense anyway, and I've
learned (or relearned) something about casting.
2014-06-12 03:47:49 +10:00
Kayne Ruse bf4a7561ed Merge branch 'client-fix' into develop (read more)
The entire repository builds cleanly, but the client is still broken and
incompatible with the server. Still, I'm merging this build into develop.

I don't know if the client runs correctly.

Much of the modifications since branching from master are untested.
2014-06-11 21:59:44 +10:00
Kayne Ruse 13332bf3fc in_combat.cpp builds; entire repo builds
Doesn't mean I'm done yet.
2014-06-11 21:57:34 +10:00
Kayne Ruse 955aed2224 in_world.cpp is building 2014-06-11 21:48:01 +10:00
Kayne Ruse ee79231de0 Began bringing the client into line with the server's changes
Several parts of the client already built correctly.

Updated LobbyMenu, it not builds.
2014-06-10 02:42:07 +10:00
Kayne Ruse 5128d17759 Merge branch 'new-map' into develop 2014-06-10 01:47:52 +10:00
Kayne Ruse a07e7418a6 Implemented a basic API for the server's rooms 2014-06-10 01:46:42 +10:00
Kayne Ruse 1ef5eb7a0f Pager's heavyweight API methods call the Region's counterparts 2014-06-10 00:52:19 +10:00
Kayne Ruse 135e650ec8 Moved the map API to the map directory 2014-06-10 00:38:00 +10:00
Kayne Ruse b7c12ba106 Fleshed out the pager's API 2014-06-10 00:20:51 +10:00
Kayne Ruse 2d27399fd1 Added the pager API placeholder files 2014-06-08 19:43:24 +10:00
Kayne Ruse ba83fac29f Changed map API to region API 2014-06-08 19:30:03 +10:00
Kayne Ruse 3bd4f1bb1d Merge branch 'new-server' (early part) into develop
Merging the server's refactored aspects into develop so that I can work on the map systems separately. See the logs for changes, because I'm too busy to add them here.
2014-06-08 19:19:08 +10:00
Kayne Ruse b269ce5fb9 Re-added the lua hooks 2014-06-08 04:20:07 +10:00
Kayne Ruse f034c32c38 Collapsed the pager into a single file, removing lua hooks
I need to re-add the lua hooks, but it'll be easy.
2014-06-08 04:01:09 +10:00
Kayne Ruse 5175a4e40d Fleshed out and rewrote some code
Fleshed out HandleCharacterNew() and HandleCharacterDelete(), and rewrote
HandleSynchronize().
2014-06-08 02:55:56 +10:00
Kayne Ruse ee2ac0b7a9 Created MAX_PACKET_SIZE 2014-06-08 00:36:05 +10:00
Kayne Ruse 63be0ee70d The server is building, but still needs work
There is some missing character creation/unloading code, and there are a
few other issues highlighted by TODO tags, see below.

In general, 'mapIndex' has been renamed to 'roomIndex'. Multiple rooms
have not been fully implemented yet, but I'm working on it.

Other issues:

* FileFormat needs to be changed to MapLoader
* Server's character movement is still slaved to the clients

The client does not build.
2014-06-07 02:15:40 +10:00
Kayne Ruse cac273da5e Partial rewrite of server_application.cpp
I've also fixed some other issues along the way. However, the next step
requires support for multiple rooms. Finally.
2014-06-07 01:14:54 +10:00
Kayne Ruse 170096b5db Server is nearly done, only server_application.cpp is failing 2014-06-06 23:34:38 +10:00
Kayne Ruse 10e857ecd1 Added empty managers for CombatData, RoomData and EnemyData
These are just placeholders for now, but I'll flesh them out later.

I should note that the server's managers all build cleanly.
2014-06-06 23:17:57 +10:00
Kayne Ruse 5c8572d811 Rearranged the methods 2014-06-06 22:57:10 +10:00
Kayne Ruse 973a2be16b Merged server_internals.cpp and network_handlers.cpp into
server_application.cpp
2014-06-06 22:11:05 +10:00
Kayne Ruse 9b9f6700af Merge commit '2c9b0fc' into develop (read more)
These changes split SerialPacket and the serialization code into more
managable chunks. I've also included some comment and error message
tweaks, just because they seem to fit into this merge rather than the
next.

I'm currently refactoring the server into more easily manageable modules,
and I might do the same to the client later. This is all to make
development easier, but I wonder if I'm just moving sideways instead of
forward.

This merge will not build.
2014-06-06 21:57:22 +10:00
Kayne Ruse 7fb458ddc1 Refactored the character management into a separate class 2014-06-06 21:53:17 +10:00
Kayne Ruse 310f701b0d Began modulating ServerApplication, beginning with the accounts 2014-06-06 21:43:54 +10:00
Kayne Ruse 6664f8a8bc Renamed server_connections.cpp => network_handlers.cpp 2014-06-06 21:14:41 +10:00
Kayne Ruse 2c9b0fc3e7 Committing some comment tweaks 2014-06-06 21:12:46 +10:00
Kayne Ruse 5966d7b51a Fleshed out the serialization internals 2014-06-04 23:30:20 +10:00
Kayne Ruse 46dff9b97b Implemented the minor changes into UDPNetworkPacket 2014-06-04 23:08:52 +10:00
Kayne Ruse 23364b2810 Split up the serial code, but had to gut it in the process
Since the contents of the packets are different than before, I decided to
gut the serialization code. I'll reimplement the internals soon.
2014-06-04 23:03:24 +10:00
Kayne Ruse da60fa8f94 Began reworking the network code
This commit devides SerialPacket into a series of different structures,
all decended from a common base class.

Using a union was not a good idea.
2014-06-04 21:16:51 +10:00
Kayne Ruse fbac14e188 Merge branch 'develop' 2014-06-02 22:42:36 +10:00
Kayne Ruse 0a03535ecb Replaced several lookups to the same object with a reference 2014-06-02 22:35:55 +10:00
Kayne Ruse 2bebfdfb97 Updated database control, character stats are saving
Just for the record, I don't like the way SAVE_CHARACTER is expanded like
that.
2014-06-02 22:22:51 +10:00
Kayne Ruse fb6fba9564 Removed BBox, renamed position to origin
I've replaced the BBox class with a pair of inline functions in
check_bounds.hpp. I've also renamed the 'position' variable to 'origin' in
several locations.

These changes are mostly to alleviate ambiguity.
2014-06-02 21:13:08 +10:00
Kayne Ruse d2f03b98dc Screwing around with some settings 2014-06-02 20:02:19 +10:00
Kayne Ruse 4acd350219 Added the restart scene 2014-06-02 00:45:57 +10:00
Kayne Ruse 9d83abbd38 Copied some boilerplate code from InWorld to InCombat 2014-06-01 23:42:30 +10:00
Kayne Ruse 1cfb814ee4 Added the rest of the combat info to the network code 2014-06-01 23:07:02 +10:00
Kayne Ruse 2e8a474792 Committing todo.txt 2014-05-29 00:30:25 +10:00
Kayne Ruse 93c41bb19c Merge branch 'develop'; major refactoring complete (read more)
Streamlined the build process, including:
* Restructured the common directory
* Moved the client's scenes up one level
* Removed the unused DEBUG flag, added the GRAPHICS flag
* Moved the server's data structures to the common/gameplay directory
* Data structures are now shared by the client and server

Other changes include:
* Created the StatisticData structure
* Removed the server's static variables
* Some progress on basic combat system framework
* CharacterData now has methods (derived from the delete PlayerCharacter)
* Client-side tables are now shared between the scenes
* Refactored UDPNetworkUtility, tying it to SerialPacket
* Added new structures to SerialPacket, and serialization
* Renamed and rearranged the SQL tables
* Solved a few other TODO tags
* Updated the license headers
2014-05-29 00:28:55 +10:00
Kayne Ruse bf922ec598 Updated the license headers
It only took me 5 months.
2014-05-29 00:16:49 +10:00
Kayne Ruse de902d2d3d Bumped the network version 2014-05-28 23:39:31 +10:00
Kayne Ruse 7b3bf24e5d Refactored UDPNetworkUtility, and tied it to SerialPacket 2014-05-28 23:22:00 +10:00
Kayne Ruse de7da81102 Solved a few items on the TODO list 2014-05-28 22:16:36 +10:00
Kayne Ruse 6428b02d85 Refactored some code from InWorld into methods in CharacterData 2014-05-28 21:25:52 +10:00
Kayne Ruse 519b8a1e36 Entire project is building cleanly again, but characters are static 2014-05-28 00:50:14 +10:00
Kayne Ruse 967f0653a1 Threaded the tables through the scenes 2014-05-27 23:59:42 +10:00
Kayne Ruse b86d393571 Moved the scenes up one directory level, subdirs no longer needed 2014-05-27 23:28:29 +10:00
Kayne Ruse 6b38501c27 Added the GRAPHICS flag, to simplify the gameplay structures 2014-05-27 23:25:07 +10:00
Kayne Ruse 5893342ad8 Removed the shared parameters structure (read more)
I've also stopped using a separate branch for sharing the CharacterData
structre. This commit won't build, mostly because I need to refactor
InWorld to handle the loss of the PlayerCharacter class.

I should probably rename SQL's tables too.
2014-05-27 22:27:30 +10:00
Kayne Ruse ac4a264f12 Merge branch 'dev-charshare' into develop (read more)
Using several branches never really works out well for me. I'm merging
these changes back into develop, because I want to undo the shared
parameters change, but that's tied up with something else. It's just
easier if I do this.
2014-05-27 21:44:55 +10:00
Kayne Ruse 43895a462a Merge branch 'dev-charshare' (early part) into develop (read more)
Moved the server's containers into the common directories, and removed the
server's static members.

This commit does build, but the next commit in 'dev-charshare' won't so
I'm merging this while I can.
2014-05-26 18:38:21 +10:00
Kayne Ruse 1bde0ed3f7 Began unifying the server and client side character classes
This commit won't build
2014-05-26 18:36:09 +10:00
Kayne Ruse d903c0df30 Removed the UID counters from the data containers 2014-05-26 17:42:55 +10:00
Kayne Ruse 9620826d65 Moved the server's data containers into common/gameplay 2014-05-26 17:29:15 +10:00
Kayne Ruse 0a71f43ef3 Implemented SharedParameters system in the client (read more)
Here are more tweaks:
* InWorld's quit event now exits to the main menu, bypassing a relayed disconnect message
* InWorld's disconnect hander no longer throws exceptions (dropped creation packet bugfix)
* CombatData's internals now point to std::pair objects
* Enemies are stored in a global list
2014-05-26 17:11:26 +10:00
Kayne Ruse a47e76845f Removed common/ from the build process, and the DEBUG flag
The common/ directory is empty, only containing more directories to be
built, and the DEBUG flag isn't being used.
2014-05-26 02:21:56 +10:00
Kayne Ruse c2eb08bd5e Restructured the common/ directory, and simplified the build process 2014-05-26 02:10:12 +10:00
Kayne Ruse 7b76e07231 Hooked up the new serial code, nothing broke 2014-05-26 01:08:10 +10:00
Kayne Ruse 1dd8042d3d Added some structures to SerialPacket, and serial.cpp
I've also created the Statistics structure for simplicity.
2014-05-26 00:49:31 +10:00
Kayne Ruse c575ee9ce1 Committing todo.txt 2014-05-24 01:48:35 +10:00
Kayne Ruse 1befc76b70 Merge branch 'develop' (read more)
Deleted in the merge:
* combat_management.cpp
* todo.txt

Amended in the merge:
* server/enemy_factory_interface.hpp
* server/server_application.hpp
* server/server_internals.cpp

That version of combat_management.cpp was not what I was looking for. I'll
try again, this time by working my way down from SerialPacket. It's worked
in the past as far as establishing a standard goes.

todo.txt was deleted in this commit, but will be carried over into the
next develop branch.

I'll release a new demo build without changing the version number, since
there are no functional changes.
2014-05-24 01:24:57 +10:00
Kayne Ruse 6a6e7f7125 Adjusted the README and tweaked some notes 2014-05-19 20:04:17 +10:00
Kayne Ruse bb6e248583 Implemented EnemyFactory, still empty 2014-05-18 03:45:36 +10:00
Kayne Ruse f7df4fba6c Wrote some basic combat management code 2014-05-18 01:48:22 +10:00
Kayne Ruse e7403be508 Minor tweak to CombatInstance 2014-05-17 02:33:02 +10:00
Kayne Ruse 873715b28c Added the "speed" statistic 2014-05-16 17:56:40 +10:00
Kayne Ruse b1d6e5a314 Mostly planning 2014-05-16 02:05:52 +10:00
Kayne Ruse f0453375c4 Stating to implement the combat system 2014-05-16 00:01:05 +10:00
Kayne Ruse e5a98efd7d Merge branch 'develop' (bugfix, read more)
Found an error in the SQL save statements; fixed.

Character positions are now saved between logins.
2014-05-13 04:37:33 +10:00
Kayne Ruse 14b330009b BUGFIX: Found an error in SQL save statements
The character's positions are now persistent between logins.
2014-05-13 04:36:59 +10:00
Kayne Ruse 288b62d3f8 Merge branch 'develop' 2014-05-13 03:26:13 +10:00
Kayne Ruse c5e8f1b3af Added account and character saving on shutdown 2014-05-13 03:25:50 +10:00
Kayne Ruse 980717f9fd Merge branch 'develop' 2014-05-13 03:01:26 +10:00
Kayne Ruse 68475eee0f Created PumpCharacterUnload 2014-05-13 02:51:50 +10:00
Kayne Ruse eeb2400e79 Rearranged the server-side object hierarchy (read more)
This has been a long-running problem for days, but I've finally
implemented a correctly working hierarchy between the ClientData,
AccountData and CharacterData objects:

CharacterData -> AccountData -> ClientData

There doesn't seem to be any issues with it right now, touch wood.
2014-05-13 02:09:00 +10:00
Kayne Ruse 01244005e9 Minor file renaming and tweaks 2014-05-13 00:23:04 +10:00
Kayne Ruse c5005b9b07 Merge branch 'develop' 2014-05-12 22:40:21 +10:00
Kayne Ruse 80a26341b1 Finished the character management, but it needs testing. 2014-05-11 20:13:27 +10:00
Kayne Ruse b7877962f1 Implemented CreateCharacter() and LoadCharacter() (read more)
There are issues with the indexes. That is, the accounts and the
characters need each other's indexes upon creation. I'll need to rectify
this now.
2014-05-10 20:30:33 +10:00
Kayne Ruse 688d064085 Merge branch 'database'
Conflicts:
	todo.txt

Merging todo.txt into the master branch, despite trying to keep it
separate.
2014-05-07 21:12:22 +10:00
Kayne Ruse 1c4d53e3ef Updated TODO, might as well merge this into the master 2014-05-07 21:07:42 +10:00
Kayne Ruse a53a134163 Merge branch 'account'
Added the "accountIndex" variable to the SerialPacket.
2014-05-07 20:55:43 +10:00
Kayne Ruse 4d12788c53 Finished the server-side modifications (read more)
* There seems to be something iffy with this branch
* The size of SerialPacket may have changed

I've implemented the accountIndex variable as best I can, but I really
shouldn't code at night. I'll need to go over the changes again before
merging this.
2014-05-07 20:55:09 +10:00
Kayne Ruse 1beb7cbd5d Began adding basic authentication 2014-05-06 21:35:07 +10:00
Kayne Ruse 8358d72a98 Merge branch 'database' (read more)
* Implemented user accounts.
* Other minor tweaks

I think the general "clientIndex" variable needs to be changed to
"accountIndex", since this will allow for much easier authentication.
2014-05-06 19:21:52 +10:00
Kayne Ruse 4ebff4a25a Minor tweaks, prepping for a merge 2014-05-06 19:18:53 +10:00
Kayne Ruse 0ff787abda Added Unloading and Deletion of user accounts 2014-05-06 18:57:49 +10:00
Kayne Ruse 9b5b48a8ab Implemented saving of user accounts (read more)
To modify an existing user account, change the in memory copy and then
call the function SaveUserAccount(uid), where uid is the index of the
modified account. If the save function is not called immediately, then the
behaviour of the server is undefined.
2014-05-06 18:33:20 +10:00
Kayne Ruse 5dd0fb9e23 BUGFIX: Signal when a duplicate account is being loaded
If a duplicate account is being created or loaded then the functions
return -1. The higher code can take it from there.
2014-05-06 16:41:08 +10:00
Kayne Ruse 7c210e04a5 Switched to using a wildcard symbol 2014-05-06 00:17:50 +10:00
Kayne Ruse 9236e02101 Merge branch 'master' into database (read more)
Conflicts:
	todo.txt (kept)

Just merging the editor's deletion into this branch, nothing else major.
2014-05-06 00:08:06 +10:00
Kayne Ruse 8f4ebf20da Removed the editor, since it isn't currently needed 2014-05-06 00:07:02 +10:00
Kayne Ruse 910e51f637 Began to implement user accounts using the database
I'm mostly just testing the waters at this stage, and i've left some debug
code in. There's no way to unload, delete, etc. the accounts, but that
comes later.
2014-05-05 23:57:07 +10:00
Kayne Ruse 92fc9b4e25 Adjusted the lua's map API, requiring a large rewrite
One the whole nothing major has changed, but I think this makes things
more logical. I just hope its stable, since I'm releasing a new tag.
2014-04-29 15:53:04 +10:00
Kayne Ruse 2b8e7241c9 Merge branch 'tweaks'; nothing major 2014-04-29 13:12:39 +10:00
Kayne Ruse 124cb3ad13 Did some renaming and comment tweaks 2014-04-29 06:34:23 +10:00
Kayne Ruse 6d3400d948 Merge branch 'network' (read more)
I've refactored the network layout. Here is a brief list of changes:

* The new player object is created server-side rather than client-side
* serial.cpp now uses macros to prevent hard-to-find logic errors
* A few method definitions have been re-ordered
* SerialPacket's internals have been slightly changed
* SerialPacket now carries a datestamp defining the network protocol
* server_application.cpp has been split into two separate files
* HandleJoinRequest() has been modified to create the new player object
2014-04-29 02:14:25 +10:00
Kayne Ruse 5031352fe3 Fixed the bug (read more)
The bug was being caused by a lack of a new player object being sent to
some clients. Fixed this by adding in the sending code, and preventing the
new entries being "registered" until the end of the HandleJoinRequest()
method.

Hopefully I can simply abstract away some of this code soon.
2014-04-29 01:47:01 +10:00
Kayne Ruse 624369f147 Discovered a bug 2014-04-27 22:46:19 +10:00
Kayne Ruse 9a7f7b8684 Rewrote the TODO list 2014-04-27 03:55:44 +10:00
Kayne Ruse fa9487c2f2 Fixed the previous bug (read more)
The bug was being caused by not assigning default values to the player
objects' internals. I've added a quick fix to these structs, but I think
it's best to expand them into proper classes now.
2014-04-27 02:37:20 +10:00
Kayne Ruse 9ec1ddab99 Exceptions are being thrown; retiring for the night
I don't know what's causing these issues, so I'm leaving it for tonight.
2014-04-26 02:48:15 +10:00
Kayne Ruse 6f1c2d0555 Merge branch 'fragmented-server' into network (read more)
I've divided the server's source into several different files. This should hopefully make it a bit easier to manage.

Please note that I do know there's an exception being thrown by the client
in this build.
2014-04-26 02:34:17 +10:00
Kayne Ruse 01b50d5590 I guess it was easier to compile the fragmented server than I thought 2014-04-26 02:31:48 +10:00
Kayne Ruse 9c673928e6 Began segmenting the server's code
I've created a separate branch for this because it's gonna be a bitch to
get compiled, and then I'll still have to ensure that the client & server
are work together correctly.

This build does not compile.
2014-04-26 02:09:32 +10:00
Kayne Ruse d55dfb90e4 Worked the new protocol into the client (read more)
I've added the handle and avatar fields back into the PlayerInfo section
in the network code, because I need to be able to load a specific file
when a new player is created. This wasn't forseen, but it's fine. i'm
leaving the fields in ClientInfo as well, because LobbyMenu is using them
to login to the server.

PlayerIndex is now a shared parameter.

I've shifted some code around in InWorld, however the overall logic is the
same.

This build (as well as the last) does not compile.
2014-04-26 01:05:31 +10:00
Kayne Ruse 235a05d006 Rearranged the SerialPacket and serialization code
The serialization code is now using macros to simplify each line, and to
prevent errors. It should be noted that, apart from the region content,
the serialization and deserialization code is essentially identical.
2014-04-25 23:50:19 +10:00
Kayne Ruse dabb7b3b2e Compiled a list of tasks
The list in todo.txt are a list of tasks that will be needed to complete
the login/user accounts overhaul, and will hopefully make the server a
persistent system.

Once the server is persistent (via the database) I can start on the combat
system.
2014-04-22 01:55:09 +10:00
Kayne Ruse e756289c2b Adjusted a few comments 2014-04-22 01:54:26 +10:00
Kayne Ruse c534158c2e Merge branch 'login' (read more)
This branch was originally intended to rewrite the login system, but I've discovered some serious problems that could not wait. See the previous commit for more information. Hopefully I can get back to this soon.

I believe this version deserves a new release tag.
2014-04-21 04:00:37 +10:00
Kayne Ruse b47191a0c1 Fixed a horrible region coordinate bug
Coordinates are supposed to be stored by their x & y, but the sizes of the
tile sheets were getting mixed in as well. When trying to store a region
at (0, 20), it was being stored at (0, 260).

Another visual bug inside the tile sheet's rendering function masked this
issue until now.

Another thing to note is that I've removed an incredibly complex system
for updating the client's map. The new system may seem complex at first,
but it is straight forward compared to what it replaced.

I've also fixed a few logarithmic lagging points in the code.
2014-04-21 03:56:48 +10:00
Kayne Ruse 6c6a025f2a Adjusted a few comments 2014-04-21 02:13:00 +10:00
Kayne Ruse 60edc97ea5 Added rejections for incompatible servers 2014-04-21 01:38:28 +10:00
Kayne Ruse a5b209d9e0 Merge branch 'login' (read more)
Made a few tweaks to the code, but the build still works, so I'm merging it into master.
2014-04-21 01:02:38 +10:00
Kayne Ruse fd673a415f Removed singleton pattern 2014-04-21 01:01:00 +10:00
Kayne Ruse 4270765146 Renamed NetworkPacket to SerialPacket, updated build 2014-04-20 23:54:59 +10:00
Kayne Ruse f56cb58dfb Revised SQL setup script, and the script function 2014-04-20 23:11:46 +10:00
Kayne Ruse f315f4bf35 Merge branch 'map' (read more)
After refactoring the map system, this new build uses the preprocessor macros to define the sizes of each region object. These macros, which are defined in region.hpp, were being used anyway; these modifications simply speed up the process by cutting out a lot of the fat.
2014-04-20 05:41:49 +10:00
Kayne Ruse 69765de433 Removed the TODO file; I think it's fairly stable again 2014-04-20 05:34:15 +10:00
Kayne Ruse 35d463d4ba Removed some annoying debugging messages 2014-04-20 05:30:08 +10:00
Kayne Ruse 894b46c5db Found the error in the format functor
I shouldn't automatically guess where an error is, since this project is
so complex.
2014-04-20 05:14:25 +10:00
Kayne Ruse eb0b18af6f Brought the programs into line, (BUG, read more)
It seems that the serialization code has a bug in it. I was expecting
something like this. When the server tries to send the region content, it
exits. I'll try and find the cause of the error, but I'm committing my
changes anyway.
2014-04-20 04:41:06 +10:00
Kayne Ruse fba183fa27 Brought the common/ directory up to date with the region's preprocessors
I really hope the serialization code still works.
2014-04-20 04:02:26 +10:00
Kayne Ruse c5a627004a Refactored the map system (read more)
The region's width, height and depth are all defined by preprocessor
macros. The rest of the map system has been updated to match. The
programs proper need to be updated as well. It would be a good idea to
include the macros' values as part of the initial communication protocols,
so that the clients don't connect to a server that is using the wrong
sized regions.
2014-04-20 03:41:08 +10:00
Kayne Ruse ac27fb0ca7 Found a list of TODO comments 2014-04-20 02:40:06 +10:00
Kayne Ruse be4a8311d5 Adjusted a few comments 2014-04-20 02:39:29 +10:00
Kayne Ruse 6d32d44fa3 Reverted some of the changes, stable 2014-04-15 23:23:15 +10:00
Kayne Ruse 9bacfb1424 Merge branch 'entity' (early part) (read more)
I've had some issues with the entity system I created, so I'm trying to
revert it right now, while also retaining the other few tweaks I've made.
2014-04-15 22:40:07 +10:00
Kayne Ruse c3464be589 The server is working correctly, using the entity system 2014-04-13 22:20:30 +10:00
Kayne Ruse 7fe71c60d0 This will not build; working on refactoring 2014-04-13 03:49:35 +10:00
Kayne Ruse 0c6537fb36 Began work on the server's generic entity system 2014-04-13 03:02:26 +10:00
Kayne Ruse 854dc0eb45 Added a link to the stable build 2014-04-08 21:24:49 +10:00
Kayne Ruse e90afb7e4a Merge branch 'net-map' 2014-04-08 21:13:17 +10:00
Kayne Ruse 0453f6becf The map paging is functional 2014-04-07 02:56:48 +10:00
Kayne Ruse c8a58ab515 Wrote a potentially buggy algorithm
This algorithm is designed to find the distance of a certain region,
however it may have been better to do a quick check, rather than worrying
how many regions were loaded at once.
2014-04-07 01:24:05 +10:00
Kayne Ruse 553f8dbfa5 Fixed some framerate issues 2014-04-06 20:53:51 +10:00
Kayne Ruse 2bacdcdab7 The basic server map is being displayed in the client 2014-04-06 03:38:58 +10:00
Kayne Ruse 99aecbfdbb The client->server->client region protocol is working 2014-04-06 02:48:43 +11:00
Kayne Ruse 27bda5dc28 Working on the client side map code (read more)
I've also added in some debug code to the map classes, because I was
hunting down a std::bad_alloc beingthrown. Turns out I forgot to set the
map sizes in the client's InWorld constructor. I'm committing the fix, and
the debug code.
2014-04-06 02:25:55 +11:00
Kayne Ruse 962f3f5dd0 Added "camera" 2014-04-05 01:56:05 +11:00
Kayne Ruse 41077b43b3 Merge branch 'network-map' 2014-03-31 21:54:22 +11:00
Kayne Ruse 4410ab892f Finished the region serial code 2014-03-31 21:40:50 +11:00
Kayne Ruse 60000cb0cf Minor tweak 2014-03-31 03:38:05 +11:00
Kayne Ruse 66b00255d5 Merge branch 'lua-api' into network-map 2014-03-31 01:32:39 +11:00
Kayne Ruse a5b68cf1fd Expaneded the lua API for Regions
I've added lua hooks for both pager functor classes. Hopefully, I haven't
missed any corner cases, because it took me a while to hunt everything
down. One issue is that the map's save directory needs to be set in the
Format class, but it'll do for now. I'll review this again when I've got
more than one map running at one time.

There should be enough here for a lua-driven map generator to be
implemented, even if it's a bit rough. I think I'll test this out in the
editor eventually, but getting the base branch's network map code going
comes first.

The current process is extremely convulted, so I need to document
everything that I've done so far, including C++ and lua functions.
2014-03-31 01:30:11 +11:00
Kayne Ruse 4cff57fe71 Established a connection between the Region objects and lua 2014-03-28 04:11:34 +11:00
Kayne Ruse 38b603fc8f Began working on the lua API for the map
The basic framework is done.
2014-03-28 03:24:14 +11:00
Kayne Ruse 47684380a9 I'm having trouble with the sequence of events 2014-03-26 00:30:10 +11:00
Kayne Ruse e4bfbfb906 Minor code tweaks, this needs a lot of forethought 2014-03-16 00:28:19 +11:00
Kayne Ruse 9db86c19f6 Implemented a macro for the serial buffer size 2014-03-15 23:36:31 +11:00
Kayne Ruse d5b551cec3 Reduced the footprint of the tiles
Also prepping for serializing the regions.
2014-03-15 23:02:21 +11:00
Kayne Ruse 7e500027e3 Loosened the requirements for constructing a MapPager
This is so that I can configure the size of the pages in the config.cfg
file.
2014-03-15 19:16:42 +11:00
Kayne Ruse dd786ba579 Merge branch 'server' (read more)
The only different between this commit and the currently stable branch is the
serialization code and a slight tweak to the server's startup sequence. I tried
to refactor the server, by moving the clientMap and playerMap into their own
wrapper classes, but that failed miserably. I need to stop getting so worked up
all the time, I've wasted way too much time already.
2014-03-11 19:04:32 +11:00
Kayne Ruse 5a57888305 Fixed the crash bug 2014-03-11 18:54:06 +11:00
Kayne Ruse 706aa5e1d7 Another worthless tweak 2014-03-10 23:56:47 +11:00
Kayne Ruse 19c1b1197d Added a brand new bug, I hate this branch 2014-03-10 23:15:57 +11:00
Kayne Ruse 5cf62f5517 Nothing special, just commiting minor changes 2014-03-09 01:51:17 +11:00
Kayne Ruse 56d02ad8d4 Working on reimplementing the player characters
I've also added EraseIf() to the manager classes.
2014-03-07 22:09:50 +11:00
Kayne Ruse 006a72174f Merge branch 'master' into server 2014-03-07 21:05:09 +11:00
Kayne Ruse 0cbc9dd9db Merge branch 'serial' into server (read more)
Conflicts:
	server/server_application.cpp (resolved)

After completing the serialization code, I'm merging it into the server's
development branch. This means that although the connection and
disconnection functionality work, I still need to test the player systems
from the new server with the new serialization code.

Immediately following this commit, I'll be merging the minor tweaks to the
editor from the master branch into this one.
2014-03-07 20:58:37 +11:00
Kayne Ruse 60c31ff56d Slight code tweak 2014-03-07 20:27:34 +11:00
Kayne Ruse 6a204643f6 Serialization is finally functional 2014-03-07 20:17:11 +11:00
Kayne Ruse 59285d1630 This isn't fucking working 2014-03-07 04:49:16 +11:00
Kayne Ruse a850d6b1af Added dummy serialization functions 2014-03-06 00:20:31 +11:00
Kayne Ruse f17fa0f345 Added lua, added db connection to PlayerManager
I've also revised the startup process a bit.
2014-03-05 00:27:21 +11:00
Kayne Ruse 756d4e770d Connection and disconnection are working correctly
I've dummied out the player code, so only the client connection code is
working. Otherwise the protocol hasn't changed.

I've also made a few other tweaks as I went along, but nothing really
major.
2014-03-04 02:48:47 +11:00
Kayne Ruse 7bb5e8ce0d Moving client and player data into manager classes
Remember: anything with "manager" in its name organizes a number of other
objects, as far as I'm concerned.

I'll eventually have a database connection in the PlayerManager class;
this'll make it easier to manage the database.
2014-03-02 23:20:37 +11:00
Kayne Ruse 975533afba Minor tweak to the editor's menu bar 2014-03-01 23:58:06 +11:00
Kayne Ruse 19749f7c87 Added grey highlighting to the debug text 2014-03-01 03:31:46 +11:00
Kayne Ruse 7703c4b0ad Merge branch 'master' into stable
Even though some parts of the new map system are a stub, I feel confident
enough to merge this branch back onto the stable branch.

On the whole, I've reduced the complexity of the system, while also allowing
acceptable restrictions.

The RegionPager class works correctly. The Update() member is empty, but it's
still usable.

I've removed TileSheetManager, so the maps can only have one tileset each;
that's fine.

The tiles are voxel integers.

The editor needs an entire overhaul. I think some of the GUI components
are too complex. The sooner I can implement the map in the main
client/server system the better.
2014-03-01 00:48:19 +11:00
Kayne Ruse dc8f594eec Tested RegionPager, removed trace statements, fixed logic errors 2014-03-01 00:39:39 +11:00
Kayne Ruse 4629b7302b Fixed Region's internals 2014-02-28 23:14:22 +11:00
Kayne Ruse 02d83d1f16 BUG: Region's memory isn't being zeroed by the looks of it 2014-02-28 03:41:03 +11:00
Kayne Ruse 91c9cef56d Working on the TileSheet class 2014-02-28 03:40:18 +11:00
Kayne Ruse f7d4912942 Merge branch 'stable' 2014-02-24 01:41:40 +11:00
Kayne Ruse eb8674b84f Moved the technical document 2014-02-24 01:41:21 +11:00
Kayne Ruse ff44e4d916 Merge branch 'stable' 2014-02-24 01:14:16 +11:00
Kayne Ruse e66540f114 Updated README 2014-02-24 01:12:42 +11:00
Kayne Ruse 639c0c70e3 RegionPager can now be instanciated with template parameters
* Fixed Region::GetX() and Region::GetY()
* Replaced calls to std::find_if with regular for loops
* Changed typing of RegionPager::regionList
** regionList now holds pointers rather than the objects themselves
* Added vestigial classes MapFileFormat and MapGenerator
** MapGenerator creates and destroys the region objects
* I'm leaving in the debugging code for now
** This includes trace statements and a basterdized main() function in
/editor/main.cpp
2014-02-24 00:34:02 +11:00
Kayne Ruse 37b02352e2 Fleshed out inherited functions
TODO:
* RegionPagerBase::Update() is a stub
* MapFileFormat
* MapGenerator
* Can replace the calls to std::find_if() with a utility function
2014-02-23 03:08:37 +11:00
Kayne Ruse 31c8bd7fd2 Split the pager class into two
I've also made the base class abstract, and the derived class a template.
Hopefully this'll let me work on different parts of the class without
major issues.

This code compiles, but since it's incomplete, I can't test it properly.
2014-02-21 03:42:02 +11:00
Kayne Ruse 808fe570a3 Added empty RegionPager 2014-02-18 01:18:04 +11:00
Kayne Ruse e706cc9d13 Completed a simple region class 2014-02-15 20:06:20 +11:00
Kayne Ruse eb02cc4b6a Removed the old map system from the editor 2014-02-11 21:56:45 +11:00
Kayne Ruse 31cca61d1c Added position data to player objects 2013-12-31 02:25:16 +11:00
Kayne Ruse 071e0d9021 I'm sick of multithreading.
I'm also sick of bastards on the internet.
2013-12-30 14:11:44 +11:00
Kayne Ruse a494bfbb38 Fixed horrible naming convention 2013-12-25 22:09:59 +11:00
Kayne Ruse baadf554cd BUGFIX: Solved server failure
Cause:

server/server_application.cpp: line 93

The last argument to std::pair was simply a call to WorldRoom's
contructor. This created a temporary object that fufilled this line, but
after the new std::pair object was added to worldRoomMap, this WorldRoom
object went out of scope.

server/server_application.cpp: line 96

When OpenRoom() was called using an object that was out of scope, the
entire server simply failed.

Solution:

Changed worldRoomMap to hold a pointer to a WorldRoom object, rather than the
object itself. The new and delete operators should be used to create and
delete WorldRoom objects respectfully.
2013-12-14 00:23:20 +11:00
Kayne Ruse 9df16fede0 WARNING: Server fails on startup
For some reason, when trying to initiate the room thread, the entire
server simply fails. There is no crash, no error message, or anything. I
have no idea what's wrong.
2013-12-11 22:22:01 +11:00
Kayne Ruse dd0ad31ac6 Tweaked README.md 2013-12-11 18:54:51 +11:00
Kayne Ruse be26c9d103 Started working on multithreaded rooms 2013-12-08 15:55:49 +11:00
Kayne Ruse a448c8fb68 Added the nightly build link to the readme 2013-12-07 03:28:41 +11:00
Kayne Ruse de1a6a050f Fixed jittery lag and client closing issues 2013-12-07 03:24:39 +11:00
Kayne Ruse 49c9abe91b Added controls, it's now MP capable 2013-12-07 02:36:48 +11:00
Kayne Ruse 3b05476689 Connections and disconnections are working across different clients 2013-12-07 01:33:27 +11:00
Kayne Ruse 1c032bfc47 Implemented client-side player creation; incomplete 2013-12-06 23:03:46 +11:00
Kayne Ruse 1a7457f650 Imported and refactored PlayerCharacter from the old branch 2013-12-06 21:00:35 +11:00
Kayne Ruse e640eda771 Moved client scenes to a sub directory, reworked build process 2013-12-06 20:22:55 +11:00
Kayne Ruse fc2b67608f Added new graphics stuff, adjusted build process 2013-12-06 18:29:55 +11:00
Kayne Ruse a3a990cc01 Added player support to the server
This code is essentially copied from the old branch, since the two
branches are now functionally identical. How much time have I wasted
rewriting this?
2013-12-06 17:47:03 +11:00
Kayne Ruse f6a4674a2f Moved networking code into high cohesion functions 2013-12-02 17:54:47 +11:00
Kayne Ruse 865620b4a8 Renamed some things, and removed Client::index 2013-12-01 18:36:18 +11:00
Kayne Ruse 1e0ed350fc Removed Multithreading, simplifying the server
Networking and multithreading working at the same time is really fucking
hard. It's better to just have the one thread, and not worry about speed
at this stage.
2013-12-01 15:21:00 +11:00
Kayne Ruse 6ccc874583 Implemented the log on and log off systems
This is a pretty straight forward port of the old version, including the
incredibly hacky server list. But I just need to remember that this is a
prototype.
2013-11-23 17:53:36 +11:00
Kayne Ruse ca86dc5fb8 Added a delay, to give the machine a rest 2013-11-23 01:25:49 +11:00
Kayne Ruse e3605e4dc5 The client is receiving the list of servers 2013-11-22 23:19:29 +11:00
Kayne Ruse cb9aef95ec Reworked NetworkQueue as a template class 2013-11-22 19:57:24 +11:00
Kayne Ruse 09f97de0e6 Added HandlePacket() to the lobby 2013-11-22 19:56:15 +11:00
Kayne Ruse f5466b9982 Added config based directories 2013-11-17 00:13:16 +11:00
Kayne Ruse e176a60d28 client to server contact 2013-11-16 23:46:59 +11:00
Kayne Ruse dc24d1b059 Committing the empty WorldRoom class 2013-11-13 02:03:25 +11:00
Kayne Ruse fa3fc18ddf Imported and updated ConfigUtility 2013-11-09 21:13:00 +11:00
Kayne Ruse c2941cd3e8 Moved the thread out of the NetworkQueue class 2013-11-09 20:04:06 +11:00
Kayne Ruse bf15a5d957 Minor tweak 2013-11-09 16:32:35 +11:00
Kayne Ruse f01463bab3 Added and tested the network queue in the server
This is a reimplementation of the old network queue, but using a class.
This still uses a separate thread, so that packets can wait if there's any
lag. Really, thinking about it, I wonder how necessary this was.

On the upside, no singletons this time. Which means that you can have
several instances of UDPNetworkManager. That's unintentional, but good to
know.
2013-11-03 00:22:41 +11:00
Kayne Ruse 54cd26b76f Removed a lot of rubbish from the server 2013-11-02 19:00:08 +11:00
Kayne Ruse 2bd8adaf69 Added an empty navigation shell to the client 2013-10-27 22:00:09 +11:00
Kayne Ruse 26eba2def6 Moved some common/* files into directories 2013-10-27 20:17:37 +11:00
Kayne Ruse 43852ce755 Hooked the two scenes together
What the hell am I doing?
2013-10-27 00:43:37 +11:00
Kayne Ruse 81fab06e3b Dummied out the load & save functions 2013-10-22 20:22:35 +11:00
Kayne Ruse 77a90f9c0c Slight refactoring 2013-10-22 20:19:09 +11:00
Kayne Ruse bc32f2a2f0 The editor scene now works correctly with the TileSheetManager 2013-10-22 19:43:20 +11:00
Kayne Ruse 76bfecd466 RegionPager now uses a reference to TileSheetManager 2013-10-22 19:35:24 +11:00
Kayne Ruse d4eb1e7b8d Checking in the test scene and test tilesets 2013-10-22 19:22:18 +11:00
Kayne Ruse 2ec307510d Revised TileSheet & TileSheetManager 2013-10-22 19:18:35 +11:00
Kayne Ruse 0b4e6003d6 Created the TileSheetManager class
This class will manage the large(ish) number of tile sheets for a specific
map.
2013-10-21 23:53:36 +11:00
Kayne Ruse 7e603ffa89 Moved the map systems into their own directory 2013-10-17 23:33:02 +11:00
Kayne Ruse 6fc8570cf4 Added the saving function 2013-10-17 23:10:43 +11:00
Kayne Ruse 0bfd916df4 Fixed inverted camera, and added RegionPager::Prune() 2013-10-17 22:18:42 +11:00
Kayne Ruse 88aee0f4f5 Created the loadGameMap() function, still incomplete
Although the overall logic of this function is finished, I still need to
write the callbacks for RegionPager's onNew and onDelete.

I've also tested this using a hand written save/index file. I've written
up a map file format by hand, and I'll be implementing it over the next
few commits.
2013-10-14 21:12:09 +11:00
Kayne Ruse 0d3c3243a0 Added a debug display 2013-10-11 20:07:57 +11:00
Kayne Ruse 871b1136c2 Pager and menu bar working together without interfering with each other 2013-10-11 01:14:02 +11:00
Kayne Ruse f64c935ffe Imported revamped GUI classes, moved map classes 2013-10-11 00:30:31 +11:00
Kayne Ruse 600ec6789b Removed debug code from the editor 2013-10-07 02:32:36 +11:00
Kayne Ruse 65a3937592 Imported the rsc/ folder from the old branch 2013-10-07 01:32:29 +11:00
Kayne Ruse 719c8f49a6 Added region highlighting 2013-10-06 19:22:26 +11:00
Kayne Ruse 29928c0b92 Added a draw function to the pager
I'm also committing some simple debugging code in the scene.
2013-10-04 02:18:10 +10:00
Kayne Ruse a88a1f7cf7 Systems are working correctly, but needs cleaning 2013-10-04 00:34:57 +10:00
Kayne Ruse 46efbfbe9a Forgot to add the license 2013-10-03 23:20:04 +10:00
Kayne Ruse 26ff8dcc8f Created RegionPager 2013-10-03 23:04:16 +10:00
Kayne Ruse 9c91e9d5fd Decoupled the TileSheet class from the Map class
I moved the rangeEnd variable into the TileSheet class, making it static.
I also tweaked the return types for a few functions in Region, and removed
the sheetIndex member from Tile.
2013-10-03 21:29:11 +10:00
Kayne Ruse 3628d3c1fd Finished the delcaration of the Map class
This is actually a lot harder than I was expecting. When I program, I
approach from the angle of "What do I need to do?" rather than "how do I do
this?" At least this is finally done, so I can get to the implementation
stage. But, as I progress, I'll need to keep in mind what I need for the
index file.

Actually, I just realized that I didn't write the index functions. Well,
it should be interesting, at least.
2013-10-01 23:02:46 +10:00
Kayne Ruse 6c9406147a Added width & height members to Tile, moved local functions to utility.*pp
I've added more members to the Tile structure, namely the width & height
of the tile. This is to fix a circular logic problem, which is too
abstract for this commit message ;)

I've also moved the local/static/inline/etc. utility functions to their
own module in the common directory, because this is just cleaner that
redefining the same code a dozen times.

The map's logic is still the same, but I need to keep moving; I've been
procrastinating far too much.
2013-10-01 21:46:34 +10:00
Kayne Ruse aae244de39 Code tweak 2013-09-25 21:27:00 +10:00
Kayne Ruse d5b14c2679 Created the TileSheet class
This is incomplete on it's own, but used as part of the whole map system,
it should work well. This class keeps track of various, seemingly
unrelated states, which are used as part of the larger map system.

Also, fixed Region's members being public.
2013-09-25 20:39:59 +10:00
Kayne Ruse a54fbfb9e9 Added static linking 2013-09-21 16:26:01 +10:00
Kayne Ruse 9cbbfe77b7 After some testing Region seems OK 2013-09-19 22:52:26 +10:00
Kayne Ruse 9b64c67068 Finished a prototype of Region, needs testing 2013-09-19 16:52:15 +10:00
Kayne Ruse de0227a1cf Demonstration of Tile & Region classes 2013-09-19 01:22:52 +10:00
Kayne Ruse 1dfeabf195 SDL_net is working 2013-09-09 12:15:26 +10:00
Kayne Ruse 6c5197f3f2 The server runs the setup scripts on startup 2013-09-05 23:02:48 +10:00
Kayne Ruse 09453cc24e Added lua and SQL, but removed lsqlite3.c
lsqlite3.c looked like a good idea for connnecting SQL and lua, but I
couldn't get it to work and rather than struggle on this, I'll write my
own library later on.
2013-09-05 20:08:50 +10:00
Kayne Ruse 4b62310158 Revised build process to include the common/ directory 2013-09-04 20:49:55 +10:00
Kayne Ruse 43f2190c3e Created the database setup script 2013-09-04 19:17:16 +10:00
Kayne Ruse 3225da6b13 Added client scenes 2013-08-31 03:27:11 +10:00
Kayne Ruse 0c233b8764 Added readme.md 2013-08-29 21:55:09 +10:00
Kayne Ruse 027d0125ef Boilerplate, boilerplate, boilerplate!!!
I've created a project for client & editor programs, by simply copying one
to the other. Right now, the client still has the editor scene, but I'll
switch that out soon.

I've also added a license header to the server's source. I don't remember
what else I did, but at this point it should theoretically build out of
the box.
2013-08-29 21:17:43 +10:00
Kayne Ruse e4884c3e18 Added more placeholder files 2013-08-29 20:35:02 +10:00
Kayne Ruse b675f516e7 Beginning to create the placeholder classes 2013-08-29 19:57:25 +10:00
Kayne Ruse d5f7363c33 Minor rename 2013-08-25 13:59:13 +10:00
Kayne Ruse 7458962ad4 Rearranged the logic 2013-08-24 23:20:43 +10:00
Kayne Ruse 0a0b61287e Started working on the room system 2013-08-11 20:39:08 +10:00
139 changed files with 8376 additions and 400 deletions
+21
View File
@@ -0,0 +1,21 @@
#Editor generated files
*.sln
*.vcproj
*.suo
*.ncb
*.user
#Directories
Release/
Debug/
Out/
#Project generated files
*.db
*.o
*.a
*.exe
#Shell files
*.bat
*.sh
+33
View File
@@ -0,0 +1,33 @@
The most recent stable build for Windows can be found [here](https://dl.dropboxusercontent.com/u/46669050/Tortuga.rar).
Tortuga is a 2D multiplayer JRPG featuring permadeath (deletion of a character upon death). The emphasis of this game is on multiplayer cooperation, exploration and customization. The game runs on customizable server software that can support up to 150 simultaneous players or more.
This game is inspired by classic 2D RPGs, as well as more modern sandbox MMOs. This project is currently independently created and funded, with the goal of creating a game that will engage user's imagination and inspire a large modding community.
## Documentation
Tortuga's full documentation can be found in a separate branch, see [Tortuga/docs](https://github.com/Ratstail91/Tortuga/tree/docs).
For Tortuga's primary documentation, please read the [Tortuga Game Design Document](https://github.com/Ratstail91/Tortuga/blob/docs/Tortuga%20Game%20Design%20Document.docx?raw=true).
## External Dependencies
* [SDL 1.2](http://www.libsdl.org/) - Simple DirectMedia Layer API
* [SDL_net 1.2](http://www.libsdl.org/projects/SDL_net/) - SDL's networking extension
* [lua 5.2](http://www.lua.org/) - The lua programming language
* [SQLite3](http://www.sqlite.org/) - A lightweight SQL database engine
## Copyright
(Future versions (to be determined) may be released under a modified version of the [Uplink Developer's License](http://www.introversion.co.uk/uplink/developer/license.html).)
The current version of Tortuga is released under the [zlib license](http://en.wikipedia.org/wiki/Zlib_License).
Copyright (c) 2013, 2014 Kayne Ruse
This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software.
Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
+4 -20
View File
@@ -19,27 +19,11 @@
* 3. This notice may not be removed or altered from any source
* distribution.
*/
#ifndef APPLICATION_HPP_
#define APPLICATION_HPP_
#ifndef CHANNELS_HPP_
#define CHANNELS_HPP_
#include "scene_list.hpp"
#include "base_scene.hpp"
class Application {
public:
Application() = default;
~Application() = default;
void Init(int argc, char** argv);
void Proc();
void Quit();
private:
//Private access members
void LoadScene(SceneList sceneIndex);
void UnloadScene();
BaseScene* activeScene = nullptr;
enum Channels {
SERVER = 0
};
#endif
@@ -5,7 +5,7 @@
* arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial Applications, and to alter it and redistribute it
* including commercial ClientApplications, and to alter it and redistribute it
* freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented; you must not
@@ -19,32 +19,52 @@
* 3. This notice may not be removed or altered from any source
* distribution.
*/
#include "application.hpp"
#include "client_application.hpp"
#include "serial.hpp"
#include <stdexcept>
#include <chrono>
#include <sstream>
//-------------------------
//Scene headers
//-------------------------
//Add the custom scene headers here
#include "shell_scene.hpp"
#include "splash_screen.hpp"
#include "main_menu.hpp"
#include "options_menu.hpp"
#include "lobby_menu.hpp"
#include "in_world.hpp"
#include "in_combat.hpp"
#include "restart.hpp"
//-------------------------
//Public access members
//-------------------------
void Application::Init(int argc, char** argv) {
void ClientApplication::Init(int argc, char** argv) {
//load the prerequisites
config.Load("rsc\\config.cfg");
//initialize SDL
if (SDL_Init(SDL_INIT_VIDEO)) {
throw(std::runtime_error("Failed to initialize SDL"));
}
BaseScene::SetScreen(800, 600, 0, SDL_HWSURFACE|SDL_DOUBLEBUF);
int w = config.Int("client.screen.w");
int h = config.Int("client.screen.h");
int f = config.Bool("client.screen.f") ? SDL_HWSURFACE|SDL_DOUBLEBUF|SDL_FULLSCREEN : SDL_HWSURFACE|SDL_DOUBLEBUF;
BaseScene::SetScreen(w ? w : 800, h ? h : 600, 0, f);
//initialize SDL_net
if (SDLNet_Init()) {
throw(std::runtime_error("Failed to initialize SDL_net"));
}
network.Open(0);
}
void Application::Proc() {
void ClientApplication::Proc() {
LoadScene(SceneList::FIRST);
//prepare the time system
@@ -79,7 +99,9 @@ void Application::Proc() {
UnloadScene();
}
void Application::Quit() {
void ClientApplication::Quit() {
network.Close();
SDLNet_Quit();
SDL_Quit();
}
@@ -87,24 +109,38 @@ void Application::Quit() {
//Private access members
//-------------------------
void Application::LoadScene(SceneList sceneIndex) {
void ClientApplication::LoadScene(SceneList sceneIndex) {
UnloadScene();
switch(sceneIndex) {
//add scene creation calls here
case SceneList::FIRST:
case SceneList::SHELL:
activeScene = new ShellScene();
case SceneList::SPLASHSCREEN:
activeScene = new SplashScreen(&config);
break;
default: {
std::ostringstream msg;
msg << "Failed to recognize the scene index: ";
msg << sceneIndex;
throw(std::logic_error(msg.str()));
}
case SceneList::MAINMENU:
activeScene = new MainMenu(&config);
break;
case SceneList::OPTIONSMENU:
activeScene = new OptionsMenu(&config);
break;
case SceneList::LOBBYMENU:
activeScene = new LobbyMenu(&config, &network, &clientIndex, &accountIndex);
break;
case SceneList::INWORLD:
activeScene = new InWorld(&config, &network, &clientIndex, &accountIndex, &characterIndex, &combatMap, &characterMap);
break;
case SceneList::INCOMBAT:
activeScene = new InCombat(&config, &network, &clientIndex, &accountIndex, &characterIndex, &combatMap, &characterMap, &enemyMap);
break;
case SceneList::RESTART:
activeScene = new Restart(&config, &network, &clientIndex, &accountIndex, &characterIndex, &combatMap, &characterMap, &enemyMap);
break;
default:
throw(std::logic_error("Failed to recognize the scene index"));
}
}
void Application::UnloadScene() {
void ClientApplication::UnloadScene() {
delete activeScene;
activeScene = nullptr;
}
+64
View File
@@ -0,0 +1,64 @@
/* Copyright: (c) Kayne Ruse 2013, 2014
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be
* appreciated but is not required.
*
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
*
* 3. This notice may not be removed or altered from any source
* distribution.
*/
#ifndef CLIENTAPPLICATION_HPP_
#define CLIENTAPPLICATION_HPP_
#include "scene_list.hpp"
#include "base_scene.hpp"
#include "config_utility.hpp"
#include "udp_network_utility.hpp"
#include "character_data.hpp"
#include "combat_data.hpp"
#include "enemy_data.hpp"
#include <map>
class ClientApplication {
public:
ClientApplication() = default;
~ClientApplication() = default;
void Init(int argc, char** argv);
void Proc();
void Quit();
private:
//Private access members
void LoadScene(SceneList sceneIndex);
void UnloadScene();
BaseScene* activeScene = nullptr;
//shared parameters
ConfigUtility config;
UDPNetworkUtility network;
int clientIndex = -1;
int accountIndex = -1;
int characterIndex = -1;
std::map<int, CombatData> combatMap;
std::map<int, CharacterData> characterMap;
std::map<int, EnemyData> enemyMap;
};
#endif
+232
View File
@@ -0,0 +1,232 @@
/* Copyright: (c) Kayne Ruse 2013, 2014
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be
* appreciated but is not required.
*
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
*
* 3. This notice may not be removed or altered from any source
* distribution.
*/
#include "in_combat.hpp"
#include "channels.hpp"
#include "utility.hpp"
#include <stdexcept>
//-------------------------
//Public access members
//-------------------------
InCombat::InCombat(
ConfigUtility* const argConfig,
UDPNetworkUtility* const argNetwork,
int* const argClientIndex,
int* const argAccountIndex,
int* const argCharacterIndex,
std::map<int, CombatData>* argCombatMap,
std::map<int, CharacterData>* argCharacterMap,
std::map<int, EnemyData>* argEnemyMap
):
config(*argConfig),
network(*argNetwork),
clientIndex(*argClientIndex),
accountIndex(*argAccountIndex),
characterIndex(*argCharacterIndex),
combatMap(*argCombatMap),
characterMap(*argCharacterMap),
enemyMap(*argEnemyMap)
{
/* //setup the utility objects
buttonImage.LoadSurface(config["dir.interface"] + "button_menu.bmp");
buttonImage.SetClipH(buttonImage.GetClipH()/3);
font.LoadSurface(config["dir.fonts"] + "pk_white_8.bmp");
//pass the utility objects
backButton.SetImage(&buttonImage);
backButton.SetFont(&font);
//set the button positions
backButton.SetX(50);
backButton.SetY(50 + buttonImage.GetClipH() * 0);
//set the button texts
backButton.SetText("Back");
//request a sync
RequestSynchronize();
*/
//debug
//
}
InCombat::~InCombat() {
//
}
//-------------------------
//Frame loop
//-------------------------
void InCombat::FrameStart() {
//
}
void InCombat::Update(double delta) {
//suck in and process all waiting packets
SerialPacket* packetBuffer = static_cast<SerialPacket*>(malloc(MAX_PACKET_SIZE));
while(network.Receive(packetBuffer)) {
HandlePacket(packetBuffer);
}
free(static_cast<void*>(packetBuffer));
//TODO: more
}
void InCombat::FrameEnd() {
//
}
void InCombat::RenderFrame() {
SDL_FillRect(GetScreen(), 0, 0);
Render(GetScreen());
SDL_Flip(GetScreen());
fps.Calculate();
}
void InCombat::Render(SDL_Surface* const screen) {
//TODO: draw the background
//TODO: draw the characters
//TODO: draw the enemies
//TODO: draw the UI
}
//-------------------------
//Event handlers
//-------------------------
void InCombat::QuitEvent() {
//exit the game AND the server
RequestDisconnect();
SetNextScene(SceneList::MAINMENU);
}
void InCombat::MouseMotion(SDL_MouseMotionEvent const& motion) {
//
}
void InCombat::MouseButtonDown(SDL_MouseButtonEvent const& button) {
//
}
void InCombat::MouseButtonUp(SDL_MouseButtonEvent const& button) {
//
}
void InCombat::KeyDown(SDL_KeyboardEvent const& key) {
switch(key.keysym.sym) {
case SDLK_ESCAPE:
QuitEvent();
break;
}
}
void InCombat::KeyUp(SDL_KeyboardEvent const& key) {
//
}
//-------------------------
//Network handlers
//-------------------------
void InCombat::HandlePacket(SerialPacket* const argPacket) {
switch(argPacket->type) {
case SerialPacketType::DISCONNECT:
HandleDisconnect(argPacket);
break;
//handle errors
default:
throw(std::runtime_error(std::string() + "Unknown SerialPacketType encountered in InCombat: " + to_string_custom(static_cast<int>(argPacket->type)) ));
break;
}
}
void InCombat::HandleDisconnect(SerialPacket* const) {
SetNextScene(SceneList::RESTART);
}
//TODO: more network handlers
//-------------------------
//Server control
//-------------------------
void InCombat::RequestSynchronize() {
ClientPacket newPacket;
//request a sync
newPacket.type = SerialPacketType::SYNCHRONIZE;
newPacket.clientIndex = clientIndex;
newPacket.accountIndex = accountIndex;
network.SendTo(Channels::SERVER, &newPacket);
}
void InCombat::SendPlayerUpdate() {
CharacterPacket newPacket;
//pack the packet
newPacket.type = SerialPacketType::CHARACTER_UPDATE;
newPacket.characterIndex = characterIndex;
//handle, avatar
newPacket.accountIndex = accountIndex;
// newPacket.roomIndex = localCharacter->roomIndex;
// newPacket.origin = localCharacter->origin;
// newPacket.motion = localCharacter->motion;
// newPacket.stats = localCharacter->stats;
//TODO: equipment
//TODO: items
//TODO: buffs
//TODO: debuffs
network.SendTo(Channels::SERVER, &newPacket);
}
void InCombat::RequestDisconnect() {
ClientPacket newPacket;
//send a disconnect request
newPacket.type = SerialPacketType::DISCONNECT;
newPacket.clientIndex = clientIndex;
newPacket.accountIndex = accountIndex;
network.SendTo(Channels::SERVER, &newPacket);
}
void InCombat::RequestShutdown() {
ClientPacket newPacket;
//send a shutdown request
newPacket.type = SerialPacketType::SHUTDOWN;
newPacket.clientIndex = clientIndex;
newPacket.accountIndex = accountIndex;
network.SendTo(Channels::SERVER, &newPacket);
}
+105
View File
@@ -0,0 +1,105 @@
/* Copyright: (c) Kayne Ruse 2013, 2014
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be
* appreciated but is not required.
*
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
*
* 3. This notice may not be removed or altered from any source
* distribution.
*/
#ifndef INCOMBAT_HPP_
#define INCOMBAT_HPP_
//network
#include "udp_network_utility.hpp"
//graphics
#include "image.hpp"
#include "raster_font.hpp"
#include "button.hpp"
//common
#include "config_utility.hpp"
#include "frame_rate.hpp"
#include "combat_data.hpp"
#include "character_data.hpp"
#include "enemy_data.hpp"
//client
#include "base_scene.hpp"
class InCombat : public BaseScene {
public:
//Public access members
InCombat(
ConfigUtility* const argConfig,
UDPNetworkUtility* const argNetwork,
int* const argClientIndex,
int* const argAccountIndex,
int* const argCharacterIndex,
std::map<int, CombatData>* argCombatMap,
std::map<int, CharacterData>* argCharacterMap,
std::map<int, EnemyData>* argEnemyMap
);
~InCombat();
protected:
//Frame loop
void FrameStart();
void Update(double delta);
void FrameEnd();
void RenderFrame();
void Render(SDL_Surface* const);
//Event handlers
void QuitEvent();
void MouseMotion(SDL_MouseMotionEvent const&);
void MouseButtonDown(SDL_MouseButtonEvent const&);
void MouseButtonUp(SDL_MouseButtonEvent const&);
void KeyDown(SDL_KeyboardEvent const&);
void KeyUp(SDL_KeyboardEvent const&);
//Network handlers
void HandlePacket(SerialPacket* const);
void HandleDisconnect(SerialPacket* const);
//TODO: more network handlers
//Server control
void RequestSynchronize();
void SendPlayerUpdate();
void RequestDisconnect();
void RequestShutdown();
//TODO: more
//shared parameters
ConfigUtility& config;
UDPNetworkUtility& network;
int& clientIndex;
int& accountIndex;
int& characterIndex;
std::map<int, CombatData>& combatMap;
std::map<int, CharacterData>& characterMap;
std::map<int, EnemyData>& enemyMap;
//graphics
//TODO: graphics
//UI
//TODO: UI
FrameRate fps;
};
#endif
+468
View File
@@ -0,0 +1,468 @@
/* Copyright: (c) Kayne Ruse 2013, 2014
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be
* appreciated but is not required.
*
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
*
* 3. This notice may not be removed or altered from any source
* distribution.
*/
#include "in_world.hpp"
#include "channels.hpp"
#include "utility.hpp"
#include <algorithm>
#include <cmath>
#include <stdexcept>
//-------------------------
//Public access members
//-------------------------
InWorld::InWorld(
ConfigUtility* const argConfig,
UDPNetworkUtility* const argNetwork,
int* const argClientIndex,
int* const argAccountIndex,
int* const argCharacterIndex,
std::map<int, CombatData>* argCombatMap,
std::map<int, CharacterData>* argCharacterMap
):
config(*argConfig),
network(*argNetwork),
clientIndex(*argClientIndex),
accountIndex(*argAccountIndex),
characterIndex(*argCharacterIndex),
combatMap(*argCombatMap),
characterMap(*argCharacterMap)
{
//setup the utility objects
buttonImage.LoadSurface(config["dir.interface"] + "button_menu.bmp");
buttonImage.SetClipH(buttonImage.GetClipH()/3);
font.LoadSurface(config["dir.fonts"] + "pk_white_8.bmp");
//pass the utility objects
disconnectButton.SetImage(&buttonImage);
disconnectButton.SetFont(&font);
shutDownButton.SetImage(&buttonImage);
shutDownButton.SetFont(&font);
//set the button positions
disconnectButton.SetX(50);
disconnectButton.SetY(50 + buttonImage.GetClipH() * 0);
shutDownButton.SetX(50);
shutDownButton.SetY(50 + buttonImage.GetClipH() * 1);
//set the button texts
disconnectButton.SetText("Disconnect");
shutDownButton.SetText("Shut Down");
//load the tilesheet
//TODO: add the tilesheet to the map system?
tileSheet.Load(config["dir.tilesets"] + "terrain.bmp", 12, 15);
//request a sync
RequestSynchronize();
//debug
//
}
InWorld::~InWorld() {
//
}
//-------------------------
//Frame loop
//-------------------------
void InWorld::FrameStart() {
//
}
void InWorld::Update(double delta) {
//suck in and process all waiting packets
SerialPacket* packetBuffer = static_cast<SerialPacket*>(malloc(MAX_PACKET_SIZE));
while(network.Receive(packetBuffer)) {
HandlePacket(packetBuffer);
}
free(static_cast<void*>(packetBuffer));
//update the characters
for (auto& it : characterMap) {
it.second.Update(delta);
}
//update the camera
if(localCharacter) {
camera.x = localCharacter->origin.x - camera.marginX;
camera.y = localCharacter->origin.y - camera.marginY;
}
//check the map
UpdateMap();
}
void InWorld::FrameEnd() {
//
}
void InWorld::RenderFrame() {
// SDL_FillRect(GetScreen(), 0, 0);
Render(GetScreen());
SDL_Flip(GetScreen());
fps.Calculate();
}
void InWorld::Render(SDL_Surface* const screen) {
//draw the map
for (std::list<Region>::iterator it = regionPager.GetContainer()->begin(); it != regionPager.GetContainer()->end(); it++) {
tileSheet.DrawRegionTo(screen, &(*it), camera.x, camera.y);
}
//draw characters
for (auto& it : characterMap) {
//TODO: drawing order according to Y origin
it.second.DrawTo(screen, camera.x, camera.y);
}
//draw UI
disconnectButton.DrawTo(screen);
shutDownButton.DrawTo(screen);
font.DrawStringTo(to_string_custom(fps.GetFrameRate()), screen, 0, 0);
}
//-------------------------
//Event handlers
//-------------------------
void InWorld::QuitEvent() {
//exit the game AND the server
RequestDisconnect();
SetNextScene(SceneList::MAINMENU);
}
void InWorld::MouseMotion(SDL_MouseMotionEvent const& motion) {
disconnectButton.MouseMotion(motion);
shutDownButton.MouseMotion(motion);
}
void InWorld::MouseButtonDown(SDL_MouseButtonEvent const& button) {
disconnectButton.MouseButtonDown(button);
shutDownButton.MouseButtonDown(button);
}
void InWorld::MouseButtonUp(SDL_MouseButtonEvent const& button) {
if (disconnectButton.MouseButtonUp(button) == Button::State::HOVER) {
RequestDisconnect();
}
if (shutDownButton.MouseButtonUp(button) == Button::State::HOVER) {
RequestShutDown();
}
}
void InWorld::KeyDown(SDL_KeyboardEvent const& key) {
switch(key.keysym.sym) {
case SDLK_ESCAPE: {
QuitEvent();
}
break;
//player movement
case SDLK_LEFT:
if (localCharacter) {
localCharacter->motion.x -= CHARACTER_WALKING_SPEED;
localCharacter->CorrectSprite();
SendPlayerUpdate();
}
break;
case SDLK_RIGHT:
if (localCharacter) {
localCharacter->motion.x += CHARACTER_WALKING_SPEED;
localCharacter->CorrectSprite();
SendPlayerUpdate();
}
break;
case SDLK_UP:
if (localCharacter) {
localCharacter->motion.y -= CHARACTER_WALKING_SPEED;
localCharacter->CorrectSprite();
SendPlayerUpdate();
}
break;
case SDLK_DOWN:
if (localCharacter) {
localCharacter->motion.y += CHARACTER_WALKING_SPEED;
localCharacter->CorrectSprite();
SendPlayerUpdate();
}
break;
}
}
void InWorld::KeyUp(SDL_KeyboardEvent const& key) {
switch(key.keysym.sym) {
//player movement
case SDLK_LEFT:
if (localCharacter) {
localCharacter->motion.x += CHARACTER_WALKING_SPEED;
localCharacter->CorrectSprite();
SendPlayerUpdate();
}
break;
case SDLK_RIGHT:
if (localCharacter) {
localCharacter->motion.x -= CHARACTER_WALKING_SPEED;
localCharacter->CorrectSprite();
SendPlayerUpdate();
}
break;
case SDLK_UP:
if (localCharacter) {
localCharacter->motion.y += CHARACTER_WALKING_SPEED;
localCharacter->CorrectSprite();
SendPlayerUpdate();
}
break;
case SDLK_DOWN:
if (localCharacter) {
localCharacter->motion.y -= CHARACTER_WALKING_SPEED;
localCharacter->CorrectSprite();
SendPlayerUpdate();
}
break;
}
}
//-------------------------
//Network handlers
//-------------------------
void InWorld::HandlePacket(SerialPacket* const argPacket) {
switch(argPacket->type) {
case SerialPacketType::DISCONNECT:
HandleDisconnect(argPacket);
break;
case SerialPacketType::CHARACTER_NEW:
HandleCharacterNew(static_cast<CharacterPacket*>(argPacket));
break;
case SerialPacketType::CHARACTER_DELETE:
HandleCharacterDelete(static_cast<CharacterPacket*>(argPacket));
break;
case SerialPacketType::CHARACTER_UPDATE:
HandleCharacterUpdate(static_cast<CharacterPacket*>(argPacket));
break;
case SerialPacketType::REGION_CONTENT:
HandleRegionContent(static_cast<RegionPacket*>(argPacket));
break;
//handle errors
default:
throw(std::runtime_error(std::string() + "Unknown SerialPacketType encountered in InWorld: " + to_string_custom(static_cast<int>(argPacket->type)) ));
break;
}
}
void InWorld::HandleDisconnect(SerialPacket* const argPacket) {
SetNextScene(SceneList::RESTART);
}
void InWorld::HandleCharacterNew(CharacterPacket* const argPacket) {
if (characterMap.find(argPacket->characterIndex) != characterMap.end()) {
throw(std::runtime_error("Cannot create duplicate characters"));
}
//create the character object
CharacterData& character = characterMap[argPacket->characterIndex];
//set the members
character.handle = argPacket->handle;
character.avatar = argPacket->avatar;
character.sprite.LoadSurface(config["dir.sprites"] + character.avatar, 4, 4);
character.roomIndex = argPacket->roomIndex;
character.origin = argPacket->origin;
character.motion = argPacket->motion;
character.stats = argPacket->stats;
character.CorrectSprite();
//catch this client's player object
if (argPacket->accountIndex == accountIndex && !localCharacter) {
characterIndex = argPacket->characterIndex;
localCharacter = &character;
//setup the camera
camera.width = GetScreen()->w;
camera.height = GetScreen()->h;
//center on the player's character
camera.marginX = (GetScreen()->w / 2 - localCharacter->sprite.GetImage()->GetClipW() / 2);
camera.marginY = (GetScreen()->h / 2 - localCharacter->sprite.GetImage()->GetClipH() / 2);
}
}
void InWorld::HandleCharacterDelete(CharacterPacket* const argPacket) {
//TODO: authenticate when own character is being deleted (linked to a TODO in the server)
//catch this client's player object
if (argPacket->characterIndex == characterIndex) {
characterIndex = -1;
localCharacter = nullptr;
}
characterMap.erase(argPacket->characterIndex);
}
void InWorld::HandleCharacterUpdate(CharacterPacket* const argPacket) {
if (characterMap.find(argPacket->characterIndex) == characterMap.end()) {
HandleCharacterNew(argPacket);
return;
}
CharacterData& character = characterMap[argPacket->characterIndex];
//other characters moving
if (argPacket->characterIndex != characterIndex) {
character.roomIndex = argPacket->roomIndex;
character.origin = argPacket->origin;
character.motion = argPacket->motion;
character.CorrectSprite();
}
}
void InWorld::HandleRegionContent(RegionPacket* const argPacket) {
//replace existing regions
regionPager.UnloadRegion(argPacket->x, argPacket->y);
regionPager.PushRegion(argPacket->region);
//clean up after the serial code
delete argPacket->region;
argPacket->region = nullptr;
}
//-------------------------
//Server control
//-------------------------
void InWorld::RequestSynchronize() {
ClientPacket newPacket;
//request a sync
newPacket.type = SerialPacketType::SYNCHRONIZE;
newPacket.clientIndex = clientIndex;
newPacket.accountIndex = accountIndex;
network.SendTo(Channels::SERVER, &newPacket);
}
void InWorld::SendPlayerUpdate() {
CharacterPacket newPacket;
//pack the packet
newPacket.type = SerialPacketType::CHARACTER_UPDATE;
newPacket.characterIndex = characterIndex;
//handle, avatar
newPacket.accountIndex = accountIndex;
newPacket.roomIndex = localCharacter->roomIndex;
newPacket.origin = localCharacter->origin;
newPacket.motion = localCharacter->motion;
newPacket.stats = localCharacter->stats;
//TODO: equipment
//TODO: items
//TODO: buffs
//TODO: debuffs
network.SendTo(Channels::SERVER, &newPacket);
}
void InWorld::RequestDisconnect() {
ClientPacket newPacket;
//send a disconnect request
newPacket.type = SerialPacketType::DISCONNECT;
newPacket.clientIndex = clientIndex;
newPacket.accountIndex = accountIndex;
network.SendTo(Channels::SERVER, &newPacket);
}
void InWorld::RequestShutDown() {
ClientPacket newPacket;
//send a shutdown request
newPacket.type = SerialPacketType::SHUTDOWN;
newPacket.clientIndex = clientIndex;
newPacket.accountIndex = accountIndex;
network.SendTo(Channels::SERVER, &newPacket);
}
void InWorld::RequestRegion(int roomIndex, int x, int y) {
RegionPacket packet;
//pack the region's data
packet.type = SerialPacketType::REGION_REQUEST;
packet.roomIndex = roomIndex;
packet.x = x;
packet.y = y;
network.SendTo(Channels::SERVER, &packet);
}
//-------------------------
//Utilities
//-------------------------
//TODO: convert this into a more generic function?; using parameters for the bounds
void InWorld::UpdateMap() {
//these represent the zone of regions that the client needs loaded, including the mandatory buffers (+1/-1)
int xStart = snapToBase(REGION_WIDTH, camera.x/tileSheet.GetTileW()) - REGION_WIDTH;
int xEnd = snapToBase(REGION_WIDTH, (camera.x+camera.width)/tileSheet.GetTileW()) + REGION_WIDTH;
int yStart = snapToBase(REGION_HEIGHT, camera.y/tileSheet.GetTileH()) - REGION_HEIGHT;
int yEnd = snapToBase(REGION_HEIGHT, (camera.y+camera.height)/tileSheet.GetTileH()) + REGION_HEIGHT;
//prune distant regions
for (std::list<Region>::iterator it = regionPager.GetContainer()->begin(); it != regionPager.GetContainer()->end(); /* EMPTY */) {
//check if the region is outside off this area
if (it->GetX() < xStart || it->GetX() > xEnd || it->GetY() < yStart || it->GetY() > yEnd) {
//clunky, but the alternative was time consuming
int tmpX = it->GetX();
int tmpY = it->GetY();
++it;
regionPager.UnloadRegion(tmpX, tmpY);
continue;
}
++it;
}
//request empty regions within this zone
for (int i = xStart; i <= xEnd; i += REGION_WIDTH) {
for (int j = yStart; j <= yEnd; j += REGION_HEIGHT) {
if (!regionPager.FindRegion(i, j)) {
RequestRegion(0, i, j);
}
}
}
}
+130
View File
@@ -0,0 +1,130 @@
/* Copyright: (c) Kayne Ruse 2013, 2014
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be
* appreciated but is not required.
*
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
*
* 3. This notice may not be removed or altered from any source
* distribution.
*/
#ifndef INWORLD_HPP_
#define INWORLD_HPP_
//maps
#include "region_pager_base.hpp"
//networking
#include "udp_network_utility.hpp"
//graphics
#include "image.hpp"
#include "raster_font.hpp"
#include "button.hpp"
#include "tile_sheet.hpp"
//common
#include "config_utility.hpp"
#include "frame_rate.hpp"
#include "combat_data.hpp"
#include "character_data.hpp"
//client
#include "base_scene.hpp"
//STL
#include <map>
class InWorld : public BaseScene {
public:
//Public access members
InWorld(
ConfigUtility* const argConfig,
UDPNetworkUtility* const argNetwork,
int* const argClientIndex,
int* const argAccountIndex,
int* const argCharacterIndex,
std::map<int, CombatData>* argCombatMap,
std::map<int, CharacterData>* argCharacterMap
);
~InWorld();
protected:
//Frame loop
void FrameStart();
void Update(double delta);
void FrameEnd();
void RenderFrame();
void Render(SDL_Surface* const);
//Event handlers
void QuitEvent();
void MouseMotion(SDL_MouseMotionEvent const&);
void MouseButtonDown(SDL_MouseButtonEvent const&);
void MouseButtonUp(SDL_MouseButtonEvent const&);
void KeyDown(SDL_KeyboardEvent const&);
void KeyUp(SDL_KeyboardEvent const&);
//Network handlers
void HandlePacket(SerialPacket* const);
void HandleDisconnect(SerialPacket* const);
void HandleCharacterNew(CharacterPacket* const);
void HandleCharacterDelete(CharacterPacket* const);
void HandleCharacterUpdate(CharacterPacket* const);
void HandleRegionContent(RegionPacket* const);
//Server control
void RequestSynchronize();
void SendPlayerUpdate();
void RequestDisconnect();
void RequestShutDown();
void RequestRegion(int roomIndex, int x, int y);
//utilities
void UpdateMap();
//shared parameters
ConfigUtility& config;
UDPNetworkUtility& network;
int& clientIndex;
int& accountIndex;
int& characterIndex;
std::map<int, CombatData>& combatMap;
std::map<int, CharacterData>& characterMap;
//graphics
Image buttonImage;
RasterFont font;
TileSheet tileSheet;
//map
RegionPagerBase regionPager;
//UI
Button disconnectButton;
Button shutDownButton;
//TODO: Review the camera
struct {
int x = 0, y = 0;
int width = 0, height = 0;
int marginX = 0, marginY = 0;
} camera;
FrameRate fps;
//game
CharacterData* localCharacter = nullptr;
};
#endif
+248
View File
@@ -0,0 +1,248 @@
/* Copyright: (c) Kayne Ruse 2013, 2014
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be
* appreciated but is not required.
*
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
*
* 3. This notice may not be removed or altered from any source
* distribution.
*/
#include "lobby_menu.hpp"
#include "channels.hpp"
#include "utility.hpp"
#include <stdexcept>
//-------------------------
//Public access members
//-------------------------
LobbyMenu::LobbyMenu(
ConfigUtility* const argConfig,
UDPNetworkUtility* const argNetwork,
int* const argClientIndex,
int* const argAccountIndex
):
config(*argConfig),
network(*argNetwork),
clientIndex(*argClientIndex),
accountIndex(*argAccountIndex)
{
//setup the utility objects
image.LoadSurface(config["dir.interface"] + "button_menu.bmp");
image.SetClipH(image.GetClipH()/3);
font.LoadSurface(config["dir.fonts"] + "pk_white_8.bmp");
//pass the utility objects
search.SetImage(&image);
search.SetFont(&font);
join.SetImage(&image);
join.SetFont(&font);
back.SetImage(&image);
back.SetFont(&font);
//set the button positions
search.SetX(50);
search.SetY(50 + image.GetClipH() * 0);
join.SetX(50);
join.SetY(50 + image.GetClipH() * 1);
back.SetX(50);
back.SetY(50 + image.GetClipH() * 2);
//set the button texts
search.SetText("Search");
join.SetText("Join");
back.SetText("Back");
//set the server list's position
listBox = {300, 50, 200, font.GetCharH()};
}
LobbyMenu::~LobbyMenu() {
//
}
//-------------------------
//Frame loop
//-------------------------
void LobbyMenu::FrameStart() {
//
}
void LobbyMenu::Update(double delta) {
//suck in and process all waiting packets
SerialPacket* packetBuffer = static_cast<SerialPacket*>(malloc(MAX_PACKET_SIZE));
while(network.Receive(packetBuffer)) {
HandlePacket(packetBuffer);
}
free(static_cast<void*>(packetBuffer));
}
void LobbyMenu::FrameEnd() {
//
}
void LobbyMenu::Render(SDL_Surface* const screen) {
//TODO: I need a proper UI system for the entire client and the editor
//UI
search.DrawTo(screen);
join.DrawTo(screen);
back.DrawTo(screen);
//TODO: draw headers for the server list
for (int i = 0; i < serverInfo.size(); i++) {
//draw the selected server's highlight
if (selection == &serverInfo[i]) {
SDL_Rect r = listBox;
r.y += i * listBox.h;
SDL_FillRect(screen, &r, SDL_MapRGB(screen->format, 255, 127, 39));
}
//draw the server name
font.DrawStringTo(serverInfo[i].name, screen, listBox.x, listBox.y + i*listBox.h);
//draw the player count
font.DrawStringTo(to_string_custom(serverInfo[i].playerCount), screen, listBox.x + listBox.w, listBox.y + i*listBox.h);
//compatible?
if (!serverInfo[i].compatible) {
font.DrawStringTo("?", screen, listBox.x - font.GetCharW(), listBox.y + i*listBox.h);
}
//TODO: ping/delay?
}
}
//-------------------------
//Event handlers
//-------------------------
void LobbyMenu::MouseMotion(SDL_MouseMotionEvent const& motion) {
search.MouseMotion(motion);
join.MouseMotion(motion);
back.MouseMotion(motion);
}
void LobbyMenu::MouseButtonDown(SDL_MouseButtonEvent const& button) {
search.MouseButtonDown(button);
join.MouseButtonDown(button);
back.MouseButtonDown(button);
}
void LobbyMenu::MouseButtonUp(SDL_MouseButtonEvent const& button) {
if (search.MouseButtonUp(button) == Button::State::HOVER) {
//broadcast to the network, or a specific server
SerialPacket packet;
packet.type = SerialPacketType::BROADCAST_REQUEST;
network.SendTo(config["server.host"].c_str(), config.Int("server.port"), &packet);
//reset the server list
serverInfo.clear();
selection = nullptr;
}
else if (join.MouseButtonUp(button) == Button::State::HOVER && selection != nullptr && selection->compatible) {
//pack the packet
ClientPacket packet;
packet.type = SerialPacketType::JOIN_REQUEST;
strncpy(packet.username, config["client.username"].c_str(), PACKET_STRING_SIZE);
//join the selected server
network.SendTo(&selection->address, &packet);
selection = nullptr;
}
else if (back.MouseButtonUp(button) == Button::State::HOVER) {
SetNextScene(SceneList::MAINMENU);
}
else if (
//has the user selected a server on the list?
//TODO: replace with regular collision checker
button.x > listBox.x &&
button.x < listBox.x + listBox.w &&
button.y > listBox.y &&
button.y < listBox.y + listBox.h * serverInfo.size()
) {
selection = &serverInfo[(button.y - listBox.y)/listBox.h];
}
else {
selection = nullptr;
}
}
void LobbyMenu::KeyDown(SDL_KeyboardEvent const& key) {
switch(key.keysym.sym) {
case SDLK_ESCAPE:
SetNextScene(SceneList::MAINMENU);
break;
}
}
void LobbyMenu::KeyUp(SDL_KeyboardEvent const& key) {
//
}
//-------------------------
//Network handlers
//-------------------------
void LobbyMenu::HandlePacket(SerialPacket* const argPacket) {
switch(argPacket->type) {
case SerialPacketType::BROADCAST_RESPONSE:
HandleBroadcastResponse(static_cast<ServerPacket*>(argPacket));
break;
case SerialPacketType::JOIN_RESPONSE:
HandleJoinResponse(static_cast<ClientPacket*>(argPacket));
break;
//handle errors
default:
throw(std::runtime_error(std::string() + "Unknown SerialPacketType encountered in LobbyMenu: " + to_string_custom(static_cast<int>(argPacket->type)) ));
break;
}
}
void LobbyMenu::HandleBroadcastResponse(ServerPacket* const argPacket) {
//extract the data
ServerInformation server;
server.address = argPacket->srcAddress;
server.name = argPacket->name;
server.playerCount = argPacket->playerCount;
server.version = argPacket->version;
//NOTE: Check compatibility here
server.compatible = server.version == NETWORK_VERSION;
//push
serverInfo.push_back(server);
}
void LobbyMenu::HandleJoinResponse(ClientPacket* const argPacket) {
clientIndex = argPacket->clientIndex;
accountIndex = argPacket->accountIndex;
network.Bind(&argPacket->srcAddress, Channels::SERVER);
SetNextScene(SceneList::INWORLD);
//send this player's character info
CharacterPacket newPacket;
newPacket.type = SerialPacketType::CHARACTER_NEW;
strncpy(newPacket.handle, config["client.handle"].c_str(), PACKET_STRING_SIZE);
strncpy(newPacket.avatar, config["client.avatar"].c_str(), PACKET_STRING_SIZE);
newPacket.accountIndex = accountIndex;
network.SendTo(Channels::SERVER, &newPacket);
}
+100
View File
@@ -0,0 +1,100 @@
/* Copyright: (c) Kayne Ruse 2013, 2014
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be
* appreciated but is not required.
*
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
*
* 3. This notice may not be removed or altered from any source
* distribution.
*/
#ifndef LOBBYMENU_HPP_
#define LOBBYMENU_HPP_
//graphics & ui
#include "image.hpp"
#include "raster_font.hpp"
#include "button.hpp"
//utilities
#include "config_utility.hpp"
#include "udp_network_utility.hpp"
//client
#include "base_scene.hpp"
//STL
#include <vector>
class LobbyMenu : public BaseScene {
public:
//Public access members
LobbyMenu(
ConfigUtility* const argConfig,
UDPNetworkUtility* const argNetwork,
int* const argClientIndex,
int* const argAccountIndex
);
~LobbyMenu();
protected:
//Frame loop
void FrameStart();
void Update(double delta);
void FrameEnd();
void Render(SDL_Surface* const);
//Event handlers
void MouseMotion(SDL_MouseMotionEvent const&);
void MouseButtonDown(SDL_MouseButtonEvent const&);
void MouseButtonUp(SDL_MouseButtonEvent const&);
void KeyDown(SDL_KeyboardEvent const&);
void KeyUp(SDL_KeyboardEvent const&);
//Network handlers
void HandlePacket(SerialPacket* const);
void HandleBroadcastResponse(ServerPacket* const);
void HandleJoinResponse(ClientPacket* const);
//shared parameters
ConfigUtility& config;
UDPNetworkUtility& network;
int& clientIndex;
int& accountIndex;
//members
Image image;
RasterFont font;
Button search;
Button join;
Button back;
//server list
struct ServerInformation {
IPaddress address;
std::string name;
int playerCount;
int version;
bool compatible;
};
std::vector<ServerInformation> serverInfo;
//a terrible hack, forgive me
//I'd love a proper gui system for this
SDL_Rect listBox;
ServerInformation* selection = nullptr;
};
#endif
+3 -3
View File
@@ -19,7 +19,7 @@
* 3. This notice may not be removed or altered from any source
* distribution.
*/
#include "application.hpp"
#include "client_application.hpp"
#include <stdexcept>
#include <iostream>
@@ -27,9 +27,9 @@
using namespace std;
int main(int argc, char** argv) {
cout << "Beginning " << argv[0] << endl;
cout << "Beginning client" << endl;
try {
Application app;
ClientApplication app;
app.Init(argc, argv);
app.Proc();
app.Quit();
+125
View File
@@ -0,0 +1,125 @@
/* Copyright: (c) Kayne Ruse 2013, 2014
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be
* appreciated but is not required.
*
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
*
* 3. This notice may not be removed or altered from any source
* distribution.
*/
#include "main_menu.hpp"
//-------------------------
//Public access members
//-------------------------
MainMenu::MainMenu(ConfigUtility* const argConfig):
config(*argConfig)
{
//setup the utility objects
image.LoadSurface(config["dir.interface"] + "button_menu.bmp");
image.SetClipH(image.GetClipH()/3);
font.LoadSurface(config["dir.fonts"] + "pk_white_8.bmp");
//pass the utility objects
startButton.SetImage(&image);
startButton.SetFont(&font);
optionsButton.SetImage(&image);
optionsButton.SetFont(&font);
quitButton.SetImage(&image);
quitButton.SetFont(&font);
//set the button positions
startButton.SetX(50);
startButton.SetY(50 + image.GetClipH() * 0);
optionsButton.SetX(50);
optionsButton.SetY(50 + image.GetClipH() * 1);
quitButton.SetX(50);
quitButton.SetY(50 + image.GetClipH() * 2);
//set the button texts
startButton.SetText("Start");
optionsButton.SetText("Options");
quitButton.SetText("Quit");
//debug
//
}
MainMenu::~MainMenu() {
//
}
//-------------------------
//Frame loop
//-------------------------
void MainMenu::FrameStart() {
//
}
void MainMenu::Update(double delta) {
//
}
void MainMenu::FrameEnd() {
//
}
void MainMenu::Render(SDL_Surface* const screen) {
startButton.DrawTo(screen);
optionsButton.DrawTo(screen);
quitButton.DrawTo(screen);
}
//-------------------------
//Event handlers
//-------------------------
void MainMenu::MouseMotion(SDL_MouseMotionEvent const& motion) {
startButton.MouseMotion(motion);
optionsButton.MouseMotion(motion);
quitButton.MouseMotion(motion);
}
void MainMenu::MouseButtonDown(SDL_MouseButtonEvent const& button) {
startButton.MouseButtonDown(button);
optionsButton.MouseButtonDown(button);
quitButton.MouseButtonDown(button);
}
void MainMenu::MouseButtonUp(SDL_MouseButtonEvent const& button) {
if (startButton.MouseButtonUp(button) == Button::State::HOVER) {
SetNextScene(SceneList::LOBBYMENU);
}
if (optionsButton.MouseButtonUp(button) == Button::State::HOVER) {
SetNextScene(SceneList::OPTIONSMENU);
}
if (quitButton.MouseButtonUp(button) == Button::State::HOVER) {
QuitEvent();
}
}
void MainMenu::KeyDown(SDL_KeyboardEvent const& key) {
switch(key.keysym.sym) {
case SDLK_ESCAPE:
QuitEvent();
break;
}
}
void MainMenu::KeyUp(SDL_KeyboardEvent const& key) {
//
}
+15 -8
View File
@@ -19,20 +19,21 @@
* 3. This notice may not be removed or altered from any source
* distribution.
*/
#ifndef SHELLSCENE_HPP_
#define SHELLSCENE_HPP_
#ifndef MAINMENU_HPP_
#define MAINMENU_HPP_
#include "base_scene.hpp"
#include "map_generator.hpp"
#include "config_utility.hpp"
#include "image.hpp"
#include "raster_font.hpp"
#include "button.hpp"
class ShellScene : public BaseScene {
class MainMenu : public BaseScene {
public:
//Public access members
ShellScene();
~ShellScene();
MainMenu(ConfigUtility* const);
~MainMenu();
protected:
//Frame loop
@@ -48,9 +49,15 @@ protected:
void KeyDown(SDL_KeyboardEvent const&);
void KeyUp(SDL_KeyboardEvent const&);
//shared parameters
ConfigUtility& config;
//members
MapGenerator generator;
Image image;
RasterFont font;
Button startButton;
Button optionsButton;
Button quitButton;
};
#endif
+37
View File
@@ -0,0 +1,37 @@
#config
INCLUDES+=. ../common/gameplay ../common/graphics ../common/map ../common/network ../common/network/packet ../common/network/serial ../common/ui ../common/utilities
LIBS+=../libcommon.a -lSDL_net -lwsock32 -liphlpapi -lmingw32 -lSDLmain -lSDL -llua
CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES)) -DGRAPHICS
#source
CXXSRC=$(wildcard *.cpp)
#objects
OBJDIR=obj
OBJ+=$(addprefix $(OBJDIR)/,$(CXXSRC:.cpp=.o))
#output
OUTDIR=../out
OUT=$(addprefix $(OUTDIR)/,client)
#targets
all: $(OBJ) $(OUT)
$(CXX) $(CXXFLAGS) -o $(OUT) $(OBJ) $(LIBS)
$(OBJ): | $(OBJDIR)
$(OUT): | $(OUTDIR)
$(OBJDIR):
mkdir $(OBJDIR)
$(OUTDIR):
mkdir $(OUTDIR)
$(OBJDIR)/%.o: %.cpp
$(CXX) $(CXXFLAGS) -c -o $@ $<
clean:
$(RM) *.o *.a *.exe
rebuild: clean all
+102
View File
@@ -0,0 +1,102 @@
/* Copyright: (c) Kayne Ruse 2013, 2014
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be
* appreciated but is not required.
*
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
*
* 3. This notice may not be removed or altered from any source
* distribution.
*/
#include "options_menu.hpp"
//-------------------------
//Public access members
//-------------------------
OptionsMenu::OptionsMenu(ConfigUtility* const argConfig):
config(*argConfig)
{
//setup the utility objects
image.LoadSurface(config["dir.interface"] + "button_menu.bmp");
image.SetClipH(image.GetClipH()/3);
font.LoadSurface(config["dir.fonts"] + "pk_white_8.bmp");
//pass the utility objects
backButton.SetImage(&image);
backButton.SetFont(&font);
//set the button positions
backButton.SetX(50);
backButton.SetY(50 + image.GetClipH() * 0);
//set the button texts
backButton.SetText("Back");
}
OptionsMenu::~OptionsMenu() {
//
}
//-------------------------
//Frame loop
//-------------------------
void OptionsMenu::FrameStart() {
//
}
void OptionsMenu::Update(double delta) {
//
}
void OptionsMenu::FrameEnd() {
//
}
void OptionsMenu::Render(SDL_Surface* const screen) {
backButton.DrawTo(screen);
font.DrawStringTo("Oh, were you looking for the options screen?", screen, 50, 30);
}
//-------------------------
//Event handlers
//-------------------------
void OptionsMenu::MouseMotion(SDL_MouseMotionEvent const& motion) {
backButton.MouseMotion(motion);
}
void OptionsMenu::MouseButtonDown(SDL_MouseButtonEvent const& button) {
backButton.MouseButtonDown(button);
}
void OptionsMenu::MouseButtonUp(SDL_MouseButtonEvent const& button) {
if (backButton.MouseButtonUp(button) == Button::State::HOVER) {
SetNextScene(SceneList::MAINMENU);
}
}
void OptionsMenu::KeyDown(SDL_KeyboardEvent const& key) {
switch(key.keysym.sym) {
case SDLK_ESCAPE:
SetNextScene(SceneList::MAINMENU);
break;
}
}
void OptionsMenu::KeyUp(SDL_KeyboardEvent const& key) {
//
}
+62
View File
@@ -0,0 +1,62 @@
/* Copyright: (c) Kayne Ruse 2013, 2014
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be
* appreciated but is not required.
*
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
*
* 3. This notice may not be removed or altered from any source
* distribution.
*/
#ifndef OPTIONSMENU_HPP_
#define OPTIONSMENU_HPP_
#include "base_scene.hpp"
#include "config_utility.hpp"
#include "image.hpp"
#include "raster_font.hpp"
#include "button.hpp"
//TODO: The options screen needs to be USED
class OptionsMenu : public BaseScene {
public:
//Public access members
OptionsMenu(ConfigUtility* const);
~OptionsMenu();
protected:
//Frame loop
void FrameStart();
void Update(double delta);
void FrameEnd();
void Render(SDL_Surface* const);
//Event handlers
void MouseMotion(SDL_MouseMotionEvent const&);
void MouseButtonDown(SDL_MouseButtonEvent const&);
void MouseButtonUp(SDL_MouseButtonEvent const&);
void KeyDown(SDL_KeyboardEvent const&);
void KeyUp(SDL_KeyboardEvent const&);
//shared parameters
ConfigUtility& config;
//members
Image image;
RasterFont font;
Button backButton;
};
#endif
+142
View File
@@ -0,0 +1,142 @@
/* Copyright: (c) Kayne Ruse 2014
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be
* appreciated but is not required.
*
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
*
* 3. This notice may not be removed or altered from any source
* distribution.
*/
#include "restart.hpp"
#include "channels.hpp"
#include <stdexcept>
//-------------------------
//Public access members
//-------------------------
Restart::Restart(
ConfigUtility* const argConfig,
UDPNetworkUtility* const argNetwork,
int* const argClientIndex,
int* const argAccountIndex,
int* const argCharacterIndex,
std::map<int, CombatData>* argCombatMap,
std::map<int, CharacterData>* argCharacterMap,
std::map<int, EnemyData>* argEnemyMap
):
config(*argConfig),
network(*argNetwork),
clientIndex(*argClientIndex),
accountIndex(*argAccountIndex),
characterIndex(*argCharacterIndex),
combatMap(*argCombatMap),
characterMap(*argCharacterMap),
enemyMap(*argEnemyMap)
{
//setup the utility objects
image.LoadSurface(config["dir.interface"] + "button_menu.bmp");
image.SetClipH(image.GetClipH()/3);
font.LoadSurface(config["dir.fonts"] + "pk_white_8.bmp");
//pass the utility objects
backButton.SetImage(&image);
backButton.SetFont(&font);
//set the button positions
backButton.SetX(50);
backButton.SetY(50 + image.GetClipH() * 0);
//set the button texts
backButton.SetText("Back");
//full reset
network.Unbind(Channels::SERVER);
clientIndex = -1;
accountIndex = -1;
characterIndex = -1;
combatMap.clear();
characterMap.clear();
enemyMap.clear();
//auto return
startTick = std::chrono::steady_clock::now();
}
Restart::~Restart() {
//
}
//-------------------------
//Frame loop
//-------------------------
void Restart::Update(double delta) {
if (std::chrono::steady_clock::now() - startTick > std::chrono::duration<int>(10)) {
QuitEvent();
}
while(network.Receive()) {
//EAT INCOMING PACKETS
}
}
void Restart::RenderFrame() {
SDL_FillRect(GetScreen(), 0, 0);
Render(GetScreen());
SDL_Flip(GetScreen());
fps.Calculate();
}
void Restart::Render(SDL_Surface* const screen) {
backButton.DrawTo(screen);
font.DrawStringTo("You have been disconnected.", screen, 50, 30);
}
//-------------------------
//Event handlers
//-------------------------
void Restart::QuitEvent() {
SetNextScene(SceneList::MAINMENU);
}
void Restart::MouseMotion(SDL_MouseMotionEvent const& motion) {
backButton.MouseMotion(motion);
}
void Restart::MouseButtonDown(SDL_MouseButtonEvent const& button) {
backButton.MouseButtonDown(button);
}
void Restart::MouseButtonUp(SDL_MouseButtonEvent const& button) {
if (backButton.MouseButtonUp(button) == Button::State::HOVER) {
QuitEvent();
}
}
void Restart::KeyDown(SDL_KeyboardEvent const& key) {
switch(key.keysym.sym) {
case SDLK_ESCAPE:
QuitEvent();
break;
}
}
void Restart::KeyUp(SDL_KeyboardEvent const& key) {
//
}
+98
View File
@@ -0,0 +1,98 @@
/* Copyright: (c) Kayne Ruse 2014
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be
* appreciated but is not required.
*
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
*
* 3. This notice may not be removed or altered from any source
* distribution.
*/
#ifndef RESTART_HPP_
#define RESTART_HPP_
//network
#include "udp_network_utility.hpp"
//graphics
#include "image.hpp"
#include "raster_font.hpp"
#include "button.hpp"
//common
#include "config_utility.hpp"
#include "frame_rate.hpp"
#include "combat_data.hpp"
#include "character_data.hpp"
#include "enemy_data.hpp"
//client
#include "base_scene.hpp"
//std namespace
#include <chrono>
class Restart : public BaseScene {
public:
//Public access members
Restart(
ConfigUtility* const argConfig,
UDPNetworkUtility* const argNetwork,
int* const argClientIndex,
int* const argAccountIndex,
int* const argCharacterIndex,
std::map<int, CombatData>* argCombatMap,
std::map<int, CharacterData>* argCharacterMap,
std::map<int, EnemyData>* argEnemyMap
);
~Restart();
protected:
//Frame loop
void Update(double delta);
void RenderFrame();
void Render(SDL_Surface* const);
//Event handlers
void QuitEvent();
void MouseMotion(SDL_MouseMotionEvent const&);
void MouseButtonDown(SDL_MouseButtonEvent const&);
void MouseButtonUp(SDL_MouseButtonEvent const&);
void KeyDown(SDL_KeyboardEvent const&);
void KeyUp(SDL_KeyboardEvent const&);
//shared parameters
ConfigUtility& config;
UDPNetworkUtility& network;
int& clientIndex;
int& accountIndex;
int& characterIndex;
std::map<int, CombatData>& combatMap;
std::map<int, CharacterData>& characterMap;
std::map<int, EnemyData>& enemyMap;
//graphics
Image image;
RasterFont font;
//UI
Button backButton;
FrameRate fps;
//auto return
std::chrono::steady_clock::time_point startTick;
};
#endif
+8 -2
View File
@@ -22,14 +22,20 @@
#ifndef SCENELIST_HPP_
#define SCENELIST_HPP_
enum SceneList {
enum class SceneList {
//these are reserved
QUIT,
CONTINUE,
FIRST,
//custom indexes
SHELL,
SPLASHSCREEN,
MAINMENU,
OPTIONSMENU,
LOBBYMENU,
INWORLD,
INCOMBAT,
RESTART,
};
#endif
+51
View File
@@ -0,0 +1,51 @@
/* Copyright: (c) Kayne Ruse 2013, 2014
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be
* appreciated but is not required.
*
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
*
* 3. This notice may not be removed or altered from any source
* distribution.
*/
#include "splash_screen.hpp"
//-------------------------
//Public access members
//-------------------------
SplashScreen::SplashScreen(ConfigUtility* const argConfig):
config(*argConfig)
{
logo.LoadSurface(config["dir.logos"] + "krstudios.bmp");
startTick = std::chrono::steady_clock::now();
}
SplashScreen::~SplashScreen() {
//
}
//-------------------------
//Frame loop
//-------------------------
void SplashScreen::Update(double delta) {
if (std::chrono::steady_clock::now() - startTick > std::chrono::duration<int>(1)) {
SetNextScene(SceneList::MAINMENU);
}
}
void SplashScreen::Render(SDL_Surface* const screen) {
logo.DrawTo(screen, (screen->w - logo.GetClipW()) / 2, (screen->h - logo.GetClipH()) / 2);
}
+51
View File
@@ -0,0 +1,51 @@
/* Copyright: (c) Kayne Ruse 2013, 2014
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be
* appreciated but is not required.
*
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
*
* 3. This notice may not be removed or altered from any source
* distribution.
*/
#ifndef SPLASHSCREEN_HPP_
#define SPLASHSCREEN_HPP_
#include "base_scene.hpp"
#include "config_utility.hpp"
#include "image.hpp"
#include <chrono>
class SplashScreen : public BaseScene {
public:
//Public access members
SplashScreen(ConfigUtility* const);
~SplashScreen();
protected:
//Frame loop
void Update(double delta);
void Render(SDL_Surface* const);
//shared parameters
ConfigUtility& config;
//members
std::chrono::steady_clock::time_point startTick;
Image logo;
};
#endif
+67
View File
@@ -0,0 +1,67 @@
/* Copyright: (c) Kayne Ruse 2014
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be
* appreciated but is not required.
*
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
*
* 3. This notice may not be removed or altered from any source
* distribution.
*/
#include "character_data.hpp"
void CharacterData::Update(double delta) {
if (motion.x && motion.y) {
origin += motion * delta * CHARACTER_WALKING_MOD;
}
else if (motion != 0) {
origin += motion * delta;
}
#ifdef GRAPHICS
sprite.Update(delta);
#endif
}
#ifdef GRAPHICS
void CharacterData::DrawTo(SDL_Surface* const dest, int camX, int camY) {
sprite.DrawTo(dest, origin.x - camX, origin.y - camY);
}
void CharacterData::CorrectSprite() {
//NOTE: These must correspond to the sprite sheet in use
if (motion.y > 0) {
sprite.SetYIndex(0);
}
else if (motion.y < 0) {
sprite.SetYIndex(1);
}
else if (motion.x > 0) {
sprite.SetYIndex(3);
}
else if (motion.x < 0) {
sprite.SetYIndex(2);
}
//animation
if (motion != 0) {
sprite.SetDelay(0.1);
}
else {
sprite.SetDelay(0);
sprite.SetXIndex(0);
}
}
#endif
+78
View File
@@ -0,0 +1,78 @@
/* Copyright: (c) Kayne Ruse 2014
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be
* appreciated but is not required.
*
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
*
* 3. This notice may not be removed or altered from any source
* distribution.
*/
#ifndef CHARACTERDATA_HPP_
#define CHARACTERDATA_HPP_
#include "vector2.hpp"
#include "statistics.hpp"
//graphics
#ifdef GRAPHICS
#include "sprite_sheet.hpp"
#endif
//std namespace
#include <string>
#include <cmath>
//the speeds that the characters move
constexpr double CHARACTER_WALKING_SPEED = 140.0;
constexpr double CHARACTER_WALKING_MOD = 1.0/sqrt(2.0);
struct CharacterData {
//metadata
int owner;
std::string handle;
std::string avatar;
//world position
int roomIndex = 0;
Vector2 origin = {0.0,0.0};
Vector2 motion = {0.0,0.0};
Vector2 bounds = {0.0,0.0};
//base statistics
Statistics stats;
//TODO: equipment
//TODO: items
//TODO: buffs
//TODO: debuffs
//methods
void Update(double delta);
#ifdef GRAPHICS
void DrawTo(SDL_Surface* const, int camX, int camY);
void CorrectSprite();
#endif
//active gameplay members
//NOTE: these are lost when unloaded
#ifdef GRAPHICS
SpriteSheet sprite;
#endif
bool inCombat = false;
int atbGauge = 0;
//TODO: stored command
};
#endif
+70
View File
@@ -0,0 +1,70 @@
/* Copyright: (c) Kayne Ruse 2014
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be
* appreciated but is not required.
*
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
*
* 3. This notice may not be removed or altered from any source
* distribution.
*/
#ifndef COMBATDATA_HPP_
#define COMBATDATA_HPP_
#include "vector2.hpp"
//gameplay members
#include "character_data.hpp"
#include "enemy_data.hpp"
//graphics
#ifdef GRAPHICS
#include "sprite_sheet.hpp"
#endif
//std namespace
#include <chrono>
#include <array>
#include <utility>
#define COMBAT_MAX_CHARACTERS 12
#define COMBAT_MAX_ENEMIES 12
struct CombatData {
enum class Terrain {
//TODO: types of combat terrains
NONE = 0,
GRASSLANDS,
};
typedef std::chrono::steady_clock Clock;
std::array<CharacterData, COMBAT_MAX_CHARACTERS> characterArray;
std::array<EnemyData, COMBAT_MAX_ENEMIES> enemyArray;
//world interaction
int mapIndex = 0;
Vector2 origin = {0.0,0.0};
Vector2 bounds = {0.0,0.0};
//time interval
Clock::time_point lastTick = Clock::now();
//graphics
#ifdef GRAPHICS
SpriteSheet sprite;
#endif
};
#endif
@@ -19,26 +19,44 @@
* 3. This notice may not be removed or altered from any source
* distribution.
*/
#ifndef MAPGENERATOR_HPP_
#define MAPGENERATOR_HPP_
#include "simple_rng.hpp"
#ifndef ENEMYDATA_HPP_
#define ENEMYDATA_HPP_
#include "vector2.hpp"
#include "statistics.hpp"
class MapGenerator {
public:
MapGenerator() = default;
~MapGenerator() = default;
//graphics
#ifdef GRAPHICS
#include "sprite_sheet.hpp"
#endif
Vector2 RawNoise(Vector2 const&);
double Influence(Vector2 const& gridPoint, Vector2 const& queryPoint, double width, double height);
double ScaledNoise(double x, double y, double width, double height);
double ScaledOctave(double x, double y, double width, double height, double octave);
double GetPixel(double x, double y, double width, double height, double octave);
//std namespace
#include <string>
private:
SimpleRNG rng;
struct EnemyData {
//metadata
std::string handle;
std::string avatar;
//gameplay
Statistics stats;
//TODO: equipment
//TODO: items
//TODO: buffs
//TODO: debuffs
//TODO: rewards
//active gameplay members
//NOTE: these are lost when unloaded
#ifdef GRAPHICS
SpriteSheet sprite;
Vector2 origin = {0.0,0.0};
Vector2 bounds = {0.0,0.0};
#endif
int tableIndex;
int atbGauge = 0;
};
#endif
#endif
+37
View File
@@ -0,0 +1,37 @@
#config
INCLUDES+=. ../utilities ../graphics
LIBS+=
CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES)) -DGRAPHICS
#source
CXXSRC=$(wildcard *.cpp)
#objects
OBJDIR=obj
OBJ+=$(addprefix $(OBJDIR)/,$(CXXSRC:.cpp=.o))
#output
OUTDIR=../..
OUT=$(addprefix $(OUTDIR)/,libcommon.a)
#targets
all: $(OBJ) $(OUT)
ar -crs $(OUT) $(OBJ)
$(OBJ): | $(OBJDIR)
$(OUT): | $(OUTDIR)
$(OBJDIR):
mkdir $(OBJDIR)
$(OUTDIR):
mkdir $(OUTDIR)
$(OBJDIR)/%.o: %.cpp
$(CXX) $(CXXFLAGS) -c -o $@ $<
clean:
$(RM) *.o *.a *.exe
rebuild: clean all
+31
View File
@@ -0,0 +1,31 @@
/* Copyright: (c) Kayne Ruse 2014
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be
* appreciated but is not required.
*
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
*
* 3. This notice may not be removed or altered from any source
* distribution.
*/
#include "character_data.hpp"
#include "combat_data.hpp"
#include "enemy_data.hpp"
#include "statistics.hpp"
/* DOCS: Sanity check, read more
* Since most/all of the files in this directory are header files, I've created
* this source file as a "sanity check", to ensure that the above header files
* are written correctly via make.
*/
+42
View File
@@ -0,0 +1,42 @@
/* Copyright: (c) Kayne Ruse 2014
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be
* appreciated but is not required.
*
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
*
* 3. This notice may not be removed or altered from any source
* distribution.
*/
#ifndef STATISTICS_HPP_
#define STATISTICS_HPP_
struct Statistics {
int level = 0;
int exp = 0;
int maxHP = 0;
int health = 0;
int maxMP = 0;
int mana = 0;
int attack = 0;
int defence = 0;
int intelligence = 0;
int resistance = 0;
int speed = 0;
float accuracy = 0.0;
float evasion = 0.0;
float luck = 0.0;
};
#endif
+2 -2
View File
@@ -1,5 +1,5 @@
#config
INCLUDES+=. ../utils
INCLUDES+=. ../map
LIBS+=
CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES))
@@ -11,7 +11,7 @@ OBJDIR=obj
OBJ+=$(addprefix $(OBJDIR)/,$(CXXSRC:.cpp=.o))
#output
OUTDIR=..
OUTDIR=../..
OUT=$(addprefix $(OUTDIR)/,libcommon.a)
#targets
+102
View File
@@ -0,0 +1,102 @@
/* Copyright: (c) Kayne Ruse 2013, 2014
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be
* appreciated but is not required.
*
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
*
* 3. This notice may not be removed or altered from any source
* distribution.
*/
#include "sprite_sheet.hpp"
#include <stdexcept>
#include <sstream>
void SpriteSheet::Update(double delta) {
if (delay && (tick += delta) >= delay) {
if (++xIndex >= xCount) {
xIndex = 0;
}
tick = 0;
}
image.SetClipX(xIndex * image.GetClipW());
image.SetClipY(yIndex * image.GetClipH());
}
SDL_Surface* SpriteSheet::LoadSurface(std::string fname, Uint16 xCellCount, Uint16 yCellCount) {
image.LoadSurface(fname);
xCount = xCellCount;
yCount = yCellCount;
image.SetClipW(image.GetSurface()->w / xCount);
image.SetClipH(image.GetSurface()->h / yCount);
xIndex = yIndex = 0;
delay = tick = 0.0;
}
SDL_Surface* SpriteSheet::SetSurface(SDL_Surface* surface, Uint16 xCellCount, Uint16 yCellCount) {
image.SetSurface(surface);
xCount = xCellCount;
yCount = yCellCount;
image.SetClipW(image.GetSurface()->w / xCount);
image.SetClipH(image.GetSurface()->h / yCount);
xIndex = yIndex = 0;
delay = tick = 0.0;
}
void SpriteSheet::FreeSurface() {
image.FreeSurface();
xCount = yCount = 0;
xIndex = yIndex = 0;
delay = tick = 0.0;
}
Uint16 SpriteSheet::SetXCount(Uint16 i) {
xIndex = 0;
return xCount = i;
}
Uint16 SpriteSheet::SetYCount(Uint16 i) {
yIndex = 0;
return yCount = i;
}
Uint16 SpriteSheet::SetXIndex(Uint16 i) {
if (i > xCount) {
std::ostringstream os;
os << "Cannot set x index to " << i;
throw(std::invalid_argument(os.str()));
}
return xIndex = i;
}
Uint16 SpriteSheet::SetYIndex(Uint16 i) {
if (i > yCount) {
std::ostringstream os;
os << "Cannot set y index to " << i;
throw(std::invalid_argument(os.str()));
}
return yIndex = i;
}
double SpriteSheet::SetDelay(double d) {
tick = 0;
return delay = d;
}
+66
View File
@@ -0,0 +1,66 @@
/* Copyright: (c) Kayne Ruse 2013, 2014
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be
* appreciated but is not required.
*
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
*
* 3. This notice may not be removed or altered from any source
* distribution.
*/
#ifndef SPRITESHEET_HPP_
#define SPRITESHEET_HPP_
#include "image.hpp"
class SpriteSheet {
public:
SpriteSheet() = default;
SpriteSheet(std::string fname, Uint16 xCellCount, Uint16 yCellCount) { LoadSurface(fname, xCellCount, yCellCount); }
SpriteSheet(SDL_Surface* surface, Uint16 xCellCount, Uint16 yCellCount) { SetSurface(surface, xCellCount, yCellCount); }
~SpriteSheet() { FreeSurface(); };
void Update(double delta);
SDL_Surface* LoadSurface(std::string fname, Uint16 xCellCount, Uint16 yCellCount);
SDL_Surface* SetSurface(SDL_Surface* surface, Uint16 xCellCount, Uint16 yCellCount);
SDL_Surface* GetSurface() { return image.GetSurface(); }
void FreeSurface();
void DrawTo(SDL_Surface* const dest, Sint16 x, Sint16 y) { image.DrawTo(dest, x, y); }
//accessors and mutators
Image* GetImage() { return &image; } //OO breaker
Uint16 SetXCount(Uint16);
Uint16 SetYCount(Uint16);
Uint16 SetXIndex(Uint16);
Uint16 SetYIndex(Uint16);
Uint16 GetXCount() const { return xCount; }
Uint16 GetYCount() const { return yCount; }
Uint16 GetXIndex() const { return xIndex; }
Uint16 GetYIndex() const { return yIndex; }
double SetDelay(double d);
double GetDelay() const { return delay; }
private:
Image image;
Uint16 xCount = 0, yCount = 0; //number of cells
Uint16 xIndex = 0, yIndex = 0; //current cell being drawn
double delay = 0.0, tick = 0.0;
};
#endif
+61
View File
@@ -0,0 +1,61 @@
/* Copyright: (c) Kayne Ruse 2014
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be
* appreciated but is not required.
*
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
*
* 3. This notice may not be removed or altered from any source
* distribution.
*/
#include "tile_sheet.hpp"
void TileSheet::Load(std::string fname, int xc, int yc) {
XCount = xc;
YCount = yc;
image.LoadSurface(fname);
image.SetClipW(image.GetClipW()/XCount);
image.SetClipH(image.GetClipH()/YCount);
}
void TileSheet::Unload() {
image.FreeSurface();
XCount = YCount = 0;
}
void TileSheet::DrawTo(SDL_Surface* const dest, int x, int y, Region::type_t tile) {
//0 is invisible
if (tile == 0) return;
image.SetClipX((tile-1) % XCount * image.GetClipW());
image.SetClipY((tile-1) / XCount * image.GetClipH());
image.DrawTo(dest, x, y);
}
void TileSheet::DrawRegionTo(SDL_Surface* const dest, Region* const region, int camX, int camY) {
Region::type_t tile = 0;
for (register int i = 0; i < REGION_WIDTH; ++i) {
for (register int j = 0; j < REGION_HEIGHT; ++j) {
for (register int k = 0; k < REGION_DEPTH; ++k) {
tile = region->GetTile(i, j, k);
//0 is invisible
if (tile == 0) continue;
image.SetClipX((tile-1) % XCount * image.GetClipW());
image.SetClipY((tile-1) / XCount * image.GetClipH());
image.DrawTo(dest,
(region->GetX() + i) * image.GetClipW() - camX,
(region->GetY() + j) * image.GetClipH() - camY);
}
}
}
}
+54
View File
@@ -0,0 +1,54 @@
/* Copyright: (c) Kayne Ruse 2014
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be
* appreciated but is not required.
*
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
*
* 3. This notice may not be removed or altered from any source
* distribution.
*/
#ifndef TILESHEET_HPP_
#define TILESHEET_HPP_
#include "region.hpp"
#include "image.hpp"
#include <string>
class TileSheet {
public:
TileSheet() = default;
TileSheet(std::string f, int x, int y) { Load(f, x, y); }
~TileSheet() = default;
void Load(std::string fname, int XCount, int YCount);
void Unload();
void DrawTo(SDL_Surface* const dest, int x, int y, Region::type_t tile);
void DrawRegionTo(SDL_Surface* const dest, Region* const region, int camX, int camY);
//accessors
Image* GetImage() { return &image; }
int GetXCount() { return XCount; }
int GetYCount() { return YCount; }
int GetTileW() { return image.GetClipW(); }
int GetTileH() { return image.GetClipH(); }
private:
Image image;
int XCount = 0, YCount = 0;
};
#endif
+12
View File
@@ -0,0 +1,12 @@
all:
$(MAKE) -C gameplay
$(MAKE) -C graphics
$(MAKE) -C map
$(MAKE) -C network
$(MAKE) -C ui
$(MAKE) -C utilities
clean:
$(RM) *.o *.a *.exe
rebuild: clean all
+5 -5
View File
@@ -1,6 +1,6 @@
#config
INCLUDES+=. ../utils ../mapgen
LIBS+=../libcommon.a -lmingw32 -lSDLmain -lSDL
INCLUDES+=. ../utilities
LIBS+=
CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES))
#source
@@ -11,12 +11,12 @@ OBJDIR=obj
OBJ+=$(addprefix $(OBJDIR)/,$(CXXSRC:.cpp=.o))
#output
OUTDIR=../out
OUT=$(addprefix $(OUTDIR)/,shell)
OUTDIR=../..
OUT=$(addprefix $(OUTDIR)/,libcommon.a)
#targets
all: $(OBJ) $(OUT)
$(CXX) $(CXXFLAGS) -o $(OUT) $(OBJ) $(LIBS)
ar -crs $(OUT) $(OBJ)
$(OBJ): | $(OBJDIR)
+156
View File
@@ -0,0 +1,156 @@
/* Copyright: (c) Kayne Ruse 2014
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be
* appreciated but is not required.
*
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
*
* 3. This notice may not be removed or altered from any source
* distribution.
*/
#include "pager_api.hpp"
#include "region_pager_lua.hpp"
#include "region.hpp"
#include <stdexcept>
#include <string>
static int setTile(lua_State* L) {
RegionPagerLua* pager = reinterpret_cast<RegionPagerLua*>(lua_touserdata(L, 1));
int ret = pager->SetTile(lua_tointeger(L, 2), lua_tointeger(L, 3), lua_tointeger(L, 4), lua_tointeger(L, 5));
lua_pushinteger(L, ret);
return 1;
}
static int getTile(lua_State* L) {
RegionPagerLua* pager = reinterpret_cast<RegionPagerLua*>(lua_touserdata(L, 1));
int ret = pager->GetTile(lua_tointeger(L, 2), lua_tointeger(L, 3), lua_tointeger(L, 4));
lua_pushinteger(L, ret);
return 1;
}
static int getRegion(lua_State* L) {
RegionPagerLua* pager = reinterpret_cast<RegionPagerLua*>(lua_touserdata(L, 1));
Region* region = pager->GetRegion(lua_tointeger(L, 2), lua_tointeger(L, 3));
lua_pushlightuserdata(L, region);
return 1;
}
static int setDirectory(lua_State* L) {
RegionPagerLua* pager = reinterpret_cast<RegionPagerLua*>(lua_touserdata(L, 1));
std::string s = pager->SetDirectory(lua_tostring(L, 2));
lua_pushstring(L, s.c_str());
return 1;
}
static int getDirectory(lua_State* L) {
RegionPagerLua* pager = reinterpret_cast<RegionPagerLua*>(lua_touserdata(L, 1));
std::string s = pager->GetDirectory();
lua_pushstring(L, s.c_str());
return 1;
}
static int loadRegion(lua_State* L) {
//get the parameters
RegionPagerLua* pager = reinterpret_cast<RegionPagerLua*>(lua_touserdata(L, 1));
Region* region = pager->GetRegion(lua_tointeger(L, 2), lua_tointeger(L, 3));
std::string s = pager->GetDirectory();
//push the parameters
lua_getglobal(L, "region");
lua_getfield(L, -1, "load");
lua_pushlightuserdata(L, region);
lua_pushstring(L, s.c_str());
//call the method
if (lua_pcall(L, 2, 1, 0) != LUA_OK) {
throw(std::runtime_error(std::string() + "Lua error: " + lua_tostring(L, -1) ));
}
return 1;
}
static int saveRegion(lua_State* L) {
//get the parameters
RegionPagerLua* pager = reinterpret_cast<RegionPagerLua*>(lua_touserdata(L, 1));
Region* region = pager->GetRegion(lua_tointeger(L, 2), lua_tointeger(L, 3));
std::string s = pager->GetDirectory();
//push the parameters
lua_getglobal(L, "region");
lua_getfield(L, -1, "save");
lua_pushlightuserdata(L, region);
lua_pushstring(L, s.c_str());
//call the method
if (lua_pcall(L, 2, 0, 0) != LUA_OK) {
throw(std::runtime_error(std::string() + "Lua error: " + lua_tostring(L, -1) ));
}
return 0;
}
static int createRegion(lua_State* L) {
//get the parameters
RegionPagerLua* pager = reinterpret_cast<RegionPagerLua*>(lua_touserdata(L, 1));
Region* region = pager->GetRegion(lua_tointeger(L, 2), lua_tointeger(L, 3));
//push the parameters
lua_getglobal(L, "region");
lua_getfield(L, -1, "create");
lua_pushlightuserdata(L, region);
//TODO: parameters
//call the method
if (lua_pcall(L, 1, 0, 0) != LUA_OK) {
throw(std::runtime_error(std::string() + "Lua error: " + lua_tostring(L, -1) ));
}
return 0;
}
static int unloadRegion(lua_State* L) {
//get the parameters
RegionPagerLua* pager = reinterpret_cast<RegionPagerLua*>(lua_touserdata(L, 1));
Region* region = pager->GetRegion(lua_tointeger(L, 2), lua_tointeger(L, 3));
std::string s = pager->GetDirectory();
//push the parameters
lua_getglobal(L, "region");
lua_getfield(L, -1, "unload");
lua_pushlightuserdata(L, region);
lua_pushstring(L, s.c_str());
//call the method
if (lua_pcall(L, 2, 0, 0) != LUA_OK) {
throw(std::runtime_error(std::string() + "Lua error: " + lua_tostring(L, -1) ));
}
return 0;
}
static const luaL_Reg pagerlib[] = {
{"settile", setTile},
{"gettile", getTile},
{"getregion", getRegion},
{"setdirectory", setDirectory},
{"getdirectory", getDirectory},
{"loadregion", loadRegion},
{"saveregion", saveRegion},
{"createregion", createRegion},
{"unloadregion", unloadRegion},
{nullptr, nullptr}
};
LUAMOD_API int luaopen_pagerapi(lua_State* L) {
luaL_newlib(L, pagerlib);
return 1;
}
+30
View File
@@ -0,0 +1,30 @@
/* Copyright: (c) Kayne Ruse 2014
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be
* appreciated but is not required.
*
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
*
* 3. This notice may not be removed or altered from any source
* distribution.
*/
#ifndef PAGERAPI_HPP_
#define PAGERAPI_HPP_
#include "lua/lua.hpp"
#define LUA_PAGERLIBNAME "pager"
LUAMOD_API int luaopen_pagerapi(lua_State* L);
#endif
+46
View File
@@ -0,0 +1,46 @@
/* Copyright: (c) Kayne Ruse 2014
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be
* appreciated but is not required.
*
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
*
* 3. This notice may not be removed or altered from any source
* distribution.
*/
#include "region.hpp"
#include "utility.hpp"
#include <stdexcept>
#include <cstring>
Region::Region(int argX, int argY): x(argX), y(argY) {
if (x != snapToBase(REGION_WIDTH, x) || y != snapToBase(REGION_HEIGHT, y)) {
throw(std::invalid_argument("Region location is off grid"));
}
memset(tiles, 0, REGION_WIDTH*REGION_HEIGHT*REGION_DEPTH*sizeof(type_t));
}
Region::Region(Region const& rhs): x(rhs.x), y(rhs.y) {
memcpy(tiles, rhs.tiles, REGION_WIDTH*REGION_HEIGHT*REGION_DEPTH*sizeof(type_t));
}
Region::type_t Region::SetTile(int x, int y, int z, type_t v) {
return tiles[x][y][z] = v;
}
Region::type_t Region::GetTile(int x, int y, int z) {
return tiles[x][y][z];
}
+51
View File
@@ -0,0 +1,51 @@
/* Copyright: (c) Kayne Ruse 2014
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be
* appreciated but is not required.
*
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
*
* 3. This notice may not be removed or altered from any source
* distribution.
*/
#ifndef REGION_HPP_
#define REGION_HPP_
constexpr int REGION_WIDTH = 20;
constexpr int REGION_HEIGHT = 20;
constexpr int REGION_DEPTH = 3;
class Region {
public:
typedef unsigned char type_t;
Region() = delete;
Region(int x, int y);
Region(Region const&);
~Region() = default;
type_t SetTile(int x, int y, int z, type_t v);
type_t GetTile(int x, int y, int z);
//accessors
int GetX() const { return x; }
int GetY() const { return y; }
private:
const int x;
const int y;
type_t tiles[REGION_WIDTH][REGION_HEIGHT][REGION_DEPTH];
};
#endif
+106
View File
@@ -0,0 +1,106 @@
/* Copyright: (c) Kayne Ruse 2014
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be
* appreciated but is not required.
*
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
*
* 3. This notice may not be removed or altered from any source
* distribution.
*/
#include "region_api.hpp"
#include "region.hpp"
static int setTile(lua_State* L) {
Region* region = reinterpret_cast<Region*>(lua_touserdata(L, 1));
int ret = region->SetTile(lua_tointeger(L, 2)-1, lua_tointeger(L, 3)-1, lua_tointeger(L, 4)-1, lua_tointeger(L, 5));
lua_pushinteger(L, ret);
return 1;
}
static int getTile(lua_State* L) {
Region* region = reinterpret_cast<Region*>(lua_touserdata(L, 1));
int ret = region->GetTile(lua_tointeger(L, 2)-1, lua_tointeger(L, 3)-1, lua_tointeger(L, 4)-1);
lua_pushinteger(L, ret);
return 1;
}
static int getX(lua_State* L) {
Region* region = reinterpret_cast<Region*>(lua_touserdata(L, 1));
lua_pushinteger(L, region->GetX());
return 1;
}
static int getY(lua_State* L) {
Region* region = reinterpret_cast<Region*>(lua_touserdata(L, 1));
lua_pushinteger(L, region->GetY());
return 1;
}
static int getWidth(lua_State* L) {
lua_pushinteger(L, REGION_WIDTH);
return 1;
}
static int getHeight(lua_State* L) {
lua_pushinteger(L, REGION_HEIGHT);
return 1;
}
static int getDepth(lua_State* L) {
lua_pushinteger(L, REGION_DEPTH);
return 1;
}
static int load(lua_State* L) {
//TODO: fill this
lua_pushboolean(L, false);
return 1;
}
static int save(lua_State* L) {
//TODO: fill this
return 0;
}
static int create(lua_State* L) {
//TODO: fill this
return 0;
}
static int unload(lua_State* L) {
//TODO: fill this
return 0;
}
static const luaL_Reg regionlib[] = {
{"settile",setTile},
{"gettile",getTile},
{"getx",getX},
{"gety",getY},
{"getwidth",getWidth},
{"getheight",getHeight},
{"getdepth",getDepth},
{"load",load},
{"save",save},
{"create",create},
{"unload",unload},
{nullptr, nullptr}
};
LUAMOD_API int luaopen_regionapi(lua_State* L) {
luaL_newlib(L, regionlib);
return 1;
}
+30
View File
@@ -0,0 +1,30 @@
/* Copyright: (c) Kayne Ruse 2014
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be
* appreciated but is not required.
*
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
*
* 3. This notice may not be removed or altered from any source
* distribution.
*/
#ifndef REGIONAPI_HPP_
#define REGIONAPI_HPP_
#include "lua/lua.hpp"
#define LUA_REGIONLIBNAME "region"
LUAMOD_API int luaopen_regionapi(lua_State* L);
#endif
+87
View File
@@ -0,0 +1,87 @@
/* Copyright: (c) Kayne Ruse 2014
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be
* appreciated but is not required.
*
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
*
* 3. This notice may not be removed or altered from any source
* distribution.
*/
#include "region_pager_base.hpp"
#include "utility.hpp"
#include <stdexcept>
#include <algorithm>
Region::type_t RegionPagerBase::SetTile(int x, int y, int z, Region::type_t v) {
Region* ptr = GetRegion(x, y);
return ptr->SetTile(x - ptr->GetX(), y - ptr->GetY(), z, v);
}
Region::type_t RegionPagerBase::GetTile(int x, int y, int z) {
Region* ptr = GetRegion(x, y);
return ptr->GetTile(x - ptr->GetX(), y - ptr->GetY(), z);
}
Region* RegionPagerBase::GetRegion(int x, int y) {
//get the region by various means
Region* ptr = nullptr;
ptr = FindRegion(x, y);
if (ptr) return ptr;
ptr = LoadRegion(x, y);
if (ptr) return ptr;
return CreateRegion(x, y);
}
Region* RegionPagerBase::FindRegion(int x, int y) {
//find the region
std::list<Region>::iterator it = find_if(regionList.begin(), regionList.end(), [x, y](Region& region) -> bool {
return region.GetX() == x && region.GetY() == y;
});
return it != regionList.end() ? &(*it) : nullptr;
}
Region* RegionPagerBase::PushRegion(Region* const ptr) {
regionList.push_front(*ptr);
return &regionList.front();
}
Region* RegionPagerBase::LoadRegion(int x, int y) {
//TODO: load the region if possible
return nullptr;
}
Region* RegionPagerBase::SaveRegion(int x, int y) {
//TODO: find & save the region
return nullptr;
}
Region* RegionPagerBase::CreateRegion(int x, int y) {
if (FindRegion(x, y)) {
throw(std::logic_error("Cannot overwrite an existing region"));
}
regionList.emplace_front(x, y);
return &regionList.front();
}
void RegionPagerBase::UnloadRegion(int x, int y) {
//custom loop, not FindRegion()
regionList.remove_if([x, y](Region& region) -> bool { return region.GetX() == x && region.GetY() == y; });
}
void RegionPagerBase::UnloadAll() {
regionList.clear();
}
+56
View File
@@ -0,0 +1,56 @@
/* Copyright: (c) Kayne Ruse 2014
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be
* appreciated but is not required.
*
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
*
* 3. This notice may not be removed or altered from any source
* distribution.
*/
#ifndef REGIONPAGERBASE_HPP_
#define REGIONPAGERBASE_HPP_
#include "region.hpp"
#include <list>
class RegionPagerBase {
public:
RegionPagerBase() = default;
virtual ~RegionPagerBase() { UnloadAll(); };
//tile manipulation
virtual Region::type_t SetTile(int x, int y, int z, Region::type_t v);
virtual Region::type_t GetTile(int x, int y, int z);
//region manipulation
virtual Region* GetRegion(int x, int y);
virtual Region* FindRegion(int x, int y);
virtual Region* PushRegion(Region* const);
virtual Region* LoadRegion(int x, int y);
virtual Region* SaveRegion(int x, int y);
virtual Region* CreateRegion(int x, int y);
virtual void UnloadRegion(int x, int y);
virtual void UnloadAll();
//accessors & mutators
std::list<Region>* GetContainer() { return &regionList; }
protected:
std::list<Region> regionList;
};
#endif
+126
View File
@@ -0,0 +1,126 @@
/* Copyright: (c) Kayne Ruse 2014
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be
* appreciated but is not required.
*
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
*
* 3. This notice may not be removed or altered from any source
* distribution.
*/
#include "region_pager_lua.hpp"
#include "utility.hpp"
#include <stdexcept>
Region* RegionPagerLua::LoadRegion(int x, int y) {
//load the region if possible
//something to work on
regionList.emplace_front(x, y);
//API hook
lua_getglobal(luaState, "region");
lua_getfield(luaState, -1, "load");
lua_pushlightuserdata(luaState, &regionList.front());
lua_pushstring(luaState, directory.c_str());
if (lua_pcall(luaState, 2, 1, 0) != LUA_OK) {
throw(std::runtime_error(std::string() + "Lua error: " + lua_tostring(luaState, -1) ));
}
//success or failure
if (!lua_toboolean(luaState, -1)) {
lua_pop(luaState, 2);
regionList.pop_front();
return nullptr;
}
lua_pop(luaState, 2);
return &regionList.front();
}
Region* RegionPagerLua::SaveRegion(int x, int y) {
//find & save the region
Region* ptr = FindRegion(x, y);
if (ptr) {
//API hook
lua_getglobal(luaState, "region");
lua_getfield(luaState, -1, "save");
lua_pushlightuserdata(luaState, ptr);
lua_pushstring(luaState, directory.c_str());
if (lua_pcall(luaState, 2, 0, 0) != LUA_OK) {
throw(std::runtime_error(std::string() + "Lua error: " + lua_tostring(luaState, -1) ));
}
lua_pop(luaState, 1);
}
return ptr;
}
Region* RegionPagerLua::CreateRegion(int x, int y) {
if (FindRegion(x, y)) {
throw(std::logic_error("Cannot overwrite an existing region"));
}
//something to work on
regionList.emplace_front(x, y);
//API hook
lua_getglobal(luaState, "region");
lua_getfield(luaState, -1, "create");
lua_pushlightuserdata(luaState, &regionList.front());
//TODO: parameters
if (lua_pcall(luaState, 1, 0, 0) != LUA_OK) {
throw(std::runtime_error(std::string() + "Lua error: " + lua_tostring(luaState, -1) ));
}
lua_pop(luaState, 1);
return &regionList.front();;
}
void RegionPagerLua::UnloadRegion(int x, int y) {
lua_getglobal(luaState, "region");
regionList.remove_if([&](Region& region) -> bool {
if (region.GetX() == x && region.GetY() == y) {
//API hook
lua_getfield(luaState, -1, "unload");
lua_pushlightuserdata(luaState, &region);
lua_pushstring(luaState, directory.c_str());
if (lua_pcall(luaState, 2, 0, 0) != LUA_OK) {
throw(std::runtime_error(std::string() + "Lua error: " + lua_tostring(luaState, -1) ));
}
return true;
}
return false;
});
lua_pop(luaState, 1);
}
void RegionPagerLua::UnloadAll() {
lua_getglobal(luaState, "region");
for (auto& it : regionList) {
//API hook
lua_getfield(luaState, -1, "unload");
lua_pushlightuserdata(luaState, &it);
lua_pushstring(luaState, directory.c_str());
if (lua_pcall(luaState, 2, 0, 0) != LUA_OK) {
throw(std::runtime_error(std::string() + "Lua error: " + lua_tostring(luaState, -1) ));
}
}
lua_pop(luaState, 1);
regionList.clear();
}
+54
View File
@@ -0,0 +1,54 @@
/* Copyright: (c) Kayne Ruse 2014
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be
* appreciated but is not required.
*
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
*
* 3. This notice may not be removed or altered from any source
* distribution.
*/
#ifndef REGIONPAGERLUA_HPP_
#define REGIONPAGERLUA_HPP_
#include "region_pager_base.hpp"
#include "lua/lua.hpp"
#include <string>
class RegionPagerLua : public RegionPagerBase {
public:
RegionPagerLua() = default;
~RegionPagerLua() = default;
//region manipulation
Region* LoadRegion(int x, int y) override;
Region* SaveRegion(int x, int y) override;
Region* CreateRegion(int x, int y) override;
void UnloadRegion(int x, int y) override;
void UnloadAll() override;
std::string SetDirectory(std::string s) { return directory = s; }
std::string GetDirectory() { return directory; }
lua_State* SetLuaState(lua_State* L) { return luaState = L; }
lua_State* GetLuaState() { return luaState; }
protected:
std::string directory;
lua_State* luaState = nullptr;
};
#endif
+39
View File
@@ -0,0 +1,39 @@
#config
INCLUDES+=. packet serial ../gameplay ../map ../utilities
LIBS+=
CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES))
#source
CXXSRC=$(wildcard *.cpp)
#objects
OBJDIR=obj
OBJ+=$(addprefix $(OBJDIR)/,$(CXXSRC:.cpp=.o))
#output
OUTDIR=../..
OUT=$(addprefix $(OUTDIR)/,libcommon.a)
#targets
all: $(OBJ) $(OUT)
ar -crs $(OUT) $(OBJ)
$(MAKE) -C packet
$(MAKE) -C serial
$(OBJ): | $(OBJDIR)
$(OUT): | $(OUTDIR)
$(OBJDIR):
mkdir $(OBJDIR)
$(OUTDIR):
mkdir $(OUTDIR)
$(OBJDIR)/%.o: %.cpp
$(CXX) $(CXXFLAGS) -c -o $@ $<
clean:
$(RM) *.o *.a *.exe
rebuild: clean all
@@ -0,0 +1,53 @@
/* Copyright: (c) Kayne Ruse 2013, 2014
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be
* appreciated but is not required.
*
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
*
* 3. This notice may not be removed or altered from any source
* distribution.
*/
#ifndef CHARACTERPACKET_HPP_
#define CHARACTERPACKET_HPP_
#include "serial_packet_base.hpp"
#include "vector2.hpp"
#include "statistics.hpp"
struct CharacterPacket : SerialPacketBase {
//identify the character
int characterIndex;
char handle[PACKET_STRING_SIZE];
char avatar[PACKET_STRING_SIZE];
//the owner
int accountIndex;
//location
int roomIndex;
Vector2 origin;
Vector2 motion;
//gameplay
Statistics stats;
//TODO: equipment
//TODO: items
//TODO: buffs
//TODO: debuffs
};
#endif
+34
View File
@@ -0,0 +1,34 @@
/* Copyright: (c) Kayne Ruse 2013, 2014
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be
* appreciated but is not required.
*
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
*
* 3. This notice may not be removed or altered from any source
* distribution.
*/
#ifndef CLIENTPACKET_HPP_
#define CLIENTPACKET_HPP_
#include "serial_packet_base.hpp"
struct ClientPacket : SerialPacketBase {
int clientIndex;
int accountIndex;
char username[PACKET_STRING_SIZE];
// char password[PACKET_STRING_SIZE]; //hashed, not currently used
};
#endif
+46
View File
@@ -0,0 +1,46 @@
/* Copyright: (c) Kayne Ruse 2013, 2014
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be
* appreciated but is not required.
*
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
*
* 3. This notice may not be removed or altered from any source
* distribution.
*/
#ifndef COMBATPACKET_HPP_
#define COMBATPACKET_HPP_
#include "serial_packet_base.hpp"
#include "combat_data.hpp"
struct CombatPacket : SerialPacketBase {
//identify the combat instance
int combatIndex;
int difficulty;
CombatData::Terrain terrainType;
//combatants
int characterArray[COMBAT_MAX_CHARACTERS];
int enemyArray[COMBAT_MAX_ENEMIES];
//location
int mapIndex;
Vector2 origin;
//TODO: rewards
};
#endif
+44
View File
@@ -0,0 +1,44 @@
/* Copyright: (c) Kayne Ruse 2013, 2014
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be
* appreciated but is not required.
*
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
*
* 3. This notice may not be removed or altered from any source
* distribution.
*/
#ifndef ENEMYPACKET_HPP_
#define ENEMYPACKET_HPP_
#include "serial_packet_base.hpp"
struct EnemyPacket : SerialPacketBase {
//identify the enemy
int enemyIndex;
char handle[PACKET_STRING_SIZE];
char avatar[PACKET_STRING_SIZE];
//gameplay
Statistics stats;
//TODO: equipment
//TODO: items
//TODO: buffs
//TODO: debuffs
//TODO: rewards
};
#endif
+37
View File
@@ -0,0 +1,37 @@
#config
INCLUDES+=. ../../gameplay ../../map ../../utilities
LIBS+=
CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES))
#source
CXXSRC=$(wildcard *.cpp)
#objects
OBJDIR=obj
OBJ+=$(addprefix $(OBJDIR)/,$(CXXSRC:.cpp=.o))
#output
OUTDIR=../../..
OUT=$(addprefix $(OUTDIR)/,libcommon.a)
#targets
all: $(OBJ) $(OUT)
ar -crs $(OUT) $(OBJ)
$(OBJ): | $(OBJDIR)
$(OUT): | $(OUTDIR)
$(OBJDIR):
mkdir $(OBJDIR)
$(OUTDIR):
mkdir $(OUTDIR)
$(OBJDIR)/%.o: %.cpp
$(CXX) $(CXXFLAGS) -c -o $@ $<
clean:
$(RM) *.o *.a *.exe
rebuild: clean all
+38
View File
@@ -0,0 +1,38 @@
/* Copyright: (c) Kayne Ruse 2013, 2014
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be
* appreciated but is not required.
*
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
*
* 3. This notice may not be removed or altered from any source
* distribution.
*/
#ifndef REGIONPACKET_HPP_
#define REGIONPACKET_HPP_
#include "serial_packet_base.hpp"
#include "region.hpp"
struct RegionPacket : SerialPacketBase {
//location/identify the region
int roomIndex;
int x, y;
//the data
Region* region;
};
#endif
+28
View File
@@ -0,0 +1,28 @@
/* Copyright: (c) Kayne Ruse 2013, 2014
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be
* appreciated but is not required.
*
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
*
* 3. This notice may not be removed or altered from any source
* distribution.
*/
#include "serial_packet.hpp"
/* DOCS: Sanity check, read more
* Since most/all of the files in this directory are header files, I've created
* this source file as a "sanity check", to ensure that the above header files
* are written correctly via make.
*/
+44
View File
@@ -0,0 +1,44 @@
/* Copyright: (c) Kayne Ruse 2013, 2014
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be
* appreciated but is not required.
*
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
*
* 3. This notice may not be removed or altered from any source
* distribution.
*/
#ifndef SERIALPACKET_HPP_
#define SERIALPACKET_HPP_
#include "character_packet.hpp"
#include "client_packet.hpp"
#include "combat_packet.hpp"
#include "enemy_packet.hpp"
#include "region_packet.hpp"
#include "server_packet.hpp"
//NOTE: SerialPacket is defined in serial_packet_base.hpp
union MaxPacket {
CharacterPacket a;
ClientPacket b;
CombatPacket c;
EnemyPacket d;
RegionPacket e;
ServerPacket f;
};
constexpr int MAX_PACKET_SIZE = sizeof(MaxPacket);
#endif
@@ -0,0 +1,46 @@
/* Copyright: (c) Kayne Ruse 2013, 2014
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be
* appreciated but is not required.
*
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
*
* 3. This notice may not be removed or altered from any source
* distribution.
*/
#ifndef SERIALPACKETBASE_HPP_
#define SERIALPACKETBASE_HPP_
#ifndef SERIALPACKET_HPP_
#error Cannot include this file without 'serial_packet.hpp'
#endif
#include "serial_packet_type.hpp"
#include "SDL/SDL_net.h"
constexpr int NETWORK_VERSION = 20140607;
constexpr int PACKET_STRING_SIZE = 100;
struct SerialPacketBase {
//members
SerialPacketType type;
IPaddress srcAddress;
virtual ~SerialPacketBase() {};
};
typedef SerialPacketBase SerialPacket;
#endif
@@ -0,0 +1,113 @@
/* Copyright: (c) Kayne Ruse 2013, 2014
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be
* appreciated but is not required.
*
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
*
* 3. This notice may not be removed or altered from any source
* distribution.
*/
#ifndef SERIALPACKETTYPE_HPP_
#define SERIALPACKETTYPE_HPP_
/* Key for the comments:
* request => response
*/
enum class SerialPacketType {
//default: there is something wrong
NONE = 0,
//keep alive
//ping => pong
PING = 1,
PONG = 2,
//search for the server list
//none => server name, player count, version info (and source address)
BROADCAST_REQUEST = 3,
BROADCAST_RESPONSE = 4,
//try to join the server
//username, and password => client index, account index
JOIN_REQUEST = 5,
JOIN_RESPONSE = 6,
JOIN_REJECTION = 7,
//mass update of all surrounding content
//character.x, character.y => packet barrage
SYNCHRONIZE = 8,
//disconnect from the server
//autentication, account index => disconnect that account
DISCONNECT = 9,
//shut down the server
//autentication => disconnect, shutdown
SHUTDOWN = 10,
//map data
//room index, region.x, region.y => room index, region.x, region.y, region content
REGION_REQUEST = 11,
REGION_CONTENT = 12,
//combat data
//TODO: system incomplete
COMBAT_NEW = 13,
COMBAT_DELETE = 14,
COMBAT_UPDATE = 15,
COMBAT_ENTER_REQUEST = 16,
COMBAT_ENTER_RESPONSE = 17,
COMBAT_EXIT_REQUEST = 18,
COMBAT_EXIT_RESPONSE = 19,
//TODO: COMBAT info
COMBAT_REJECTION = 20,
//character data
//character data => etc.
CHARACTER_NEW = 21,
CHARACTER_DELETE = 22,
CHARACTER_UPDATE = 23,
//authentication, character index => character stats
CHARACTER_STATS_REQUEST= 24,
CHARACTER_STATS_RESPONSE = 25,
//character new => character rejection, disconnect?
CHARACTER_REJECTION = 26,
//enemy data
//enemy data => etc.
ENEMY_NEW = 27,
ENEMY_DELETE = 28,
ENEMY_UPDATE = 29,
ENEMY_STATS_REQUEST = 30,
ENEMY_STATS_RESPONSE = 31,
//enemy index => enemy doens't exist
ENEMY_REJECTION= 32,
//NOTE: more packet types go here
//not used
LAST
};
#endif
+34
View File
@@ -0,0 +1,34 @@
/* Copyright: (c) Kayne Ruse 2013, 2014
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be
* appreciated but is not required.
*
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
*
* 3. This notice may not be removed or altered from any source
* distribution.
*/
#ifndef SERVERPACKET_HPP_
#define SERVERPACKET_HPP_
#include "serial_packet_base.hpp"
struct ServerPacket : SerialPacketBase {
//identify the server
char name[PACKET_STRING_SIZE];
int playerCount;
int version;
};
#endif
+37
View File
@@ -0,0 +1,37 @@
#config
INCLUDES+=. ../packet ../../gameplay ../../map ../../utilities
LIBS+=
CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES))
#source
CXXSRC=$(wildcard *.cpp)
#objects
OBJDIR=obj
OBJ+=$(addprefix $(OBJDIR)/,$(CXXSRC:.cpp=.o))
#output
OUTDIR=../../..
OUT=$(addprefix $(OUTDIR)/,libcommon.a)
#targets
all: $(OBJ) $(OUT)
ar -crs $(OUT) $(OBJ)
$(OBJ): | $(OBJDIR)
$(OUT): | $(OUTDIR)
$(OBJDIR):
mkdir $(OBJDIR)
$(OUTDIR):
mkdir $(OUTDIR)
$(OBJDIR)/%.o: %.cpp
$(CXX) $(CXXFLAGS) -c -o $@ $<
clean:
$(RM) *.o *.a *.exe
rebuild: clean all
+183
View File
@@ -0,0 +1,183 @@
/* Copyright: (c) Kayne Ruse 2014
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be
* appreciated but is not required.
*
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
*
* 3. This notice may not be removed or altered from any source
* distribution.
*/
#include "serial.hpp"
#include "serial_util.hpp"
//simple type functions
void serializeType(SerialPacketBase* packet, void* buffer) {
SERIALIZE(buffer, &packet->type, sizeof(SerialPacketType));
}
void deserializeType(SerialPacketBase* packet, void* buffer) {
DESERIALIZE(buffer, &packet->type, sizeof(SerialPacketType));
}
//main switch functions
void serializePacket(SerialPacketBase* packet, void* buffer) {
switch(packet->type) {
//no extra data
case SerialPacketType::NONE:
case SerialPacketType::PING:
case SerialPacketType::PONG:
case SerialPacketType::BROADCAST_REQUEST:
//all rejections
case SerialPacketType::JOIN_REJECTION:
case SerialPacketType::CHARACTER_REJECTION:
case SerialPacketType::ENEMY_REJECTION:
case SerialPacketType::COMBAT_REJECTION:
serializeType(packet, buffer);
break;
//character info
case SerialPacketType::CHARACTER_NEW:
case SerialPacketType::CHARACTER_DELETE:
case SerialPacketType::CHARACTER_UPDATE:
case SerialPacketType::CHARACTER_STATS_REQUEST:
case SerialPacketType::CHARACTER_STATS_RESPONSE:
serializeCharacter(static_cast<CharacterPacket*>(packet), buffer);
break;
//client info
case SerialPacketType::JOIN_REQUEST:
case SerialPacketType::JOIN_RESPONSE:
case SerialPacketType::SYNCHRONIZE:
case SerialPacketType::DISCONNECT:
case SerialPacketType::SHUTDOWN:
serializeClient(static_cast<ClientPacket*>(packet), buffer);
break;
//combat info
case SerialPacketType::COMBAT_NEW:
case SerialPacketType::COMBAT_DELETE:
case SerialPacketType::COMBAT_UPDATE:
case SerialPacketType::COMBAT_ENTER_REQUEST:
case SerialPacketType::COMBAT_ENTER_RESPONSE:
case SerialPacketType::COMBAT_EXIT_REQUEST:
case SerialPacketType::COMBAT_EXIT_RESPONSE:
serializeCombat(static_cast<CombatPacket*>(packet), buffer);
break;
//enemy info
case SerialPacketType::ENEMY_NEW:
case SerialPacketType::ENEMY_DELETE:
case SerialPacketType::ENEMY_UPDATE:
case SerialPacketType::ENEMY_STATS_REQUEST:
case SerialPacketType::ENEMY_STATS_RESPONSE:
serializeEnemy(static_cast<EnemyPacket*>(packet), buffer);
break;
//region info
case SerialPacketType::REGION_REQUEST:
serializeRegionFormat(static_cast<RegionPacket*>(packet), buffer);
break;
case SerialPacketType::REGION_CONTENT:
serializeRegionContent(static_cast<RegionPacket*>(packet), buffer);
break;
//server info
case SerialPacketType::BROADCAST_RESPONSE:
serializeServer(static_cast<ServerPacket*>(packet), buffer);
break;
}
}
void deserializePacket(SerialPacketBase* packet, void* buffer) {
//find the type, so that you can actually deserialize the packet!
deserializeType(packet, buffer);
switch(packet->type) {
//no extra data
case SerialPacketType::NONE:
case SerialPacketType::PING:
case SerialPacketType::PONG:
case SerialPacketType::BROADCAST_REQUEST:
//all rejections
case SerialPacketType::JOIN_REJECTION:
case SerialPacketType::CHARACTER_REJECTION:
case SerialPacketType::ENEMY_REJECTION:
case SerialPacketType::COMBAT_REJECTION:
//NOTHING
break;
//character info
case SerialPacketType::CHARACTER_NEW:
case SerialPacketType::CHARACTER_DELETE:
case SerialPacketType::CHARACTER_UPDATE:
case SerialPacketType::CHARACTER_STATS_REQUEST:
case SerialPacketType::CHARACTER_STATS_RESPONSE:
deserializeCharacter(static_cast<CharacterPacket*>(packet), buffer);
break;
//client info
case SerialPacketType::JOIN_REQUEST:
case SerialPacketType::JOIN_RESPONSE:
case SerialPacketType::SYNCHRONIZE:
case SerialPacketType::DISCONNECT:
case SerialPacketType::SHUTDOWN:
deserializeClient(static_cast<ClientPacket*>(packet), buffer);
break;
//combat info
case SerialPacketType::COMBAT_NEW:
case SerialPacketType::COMBAT_DELETE:
case SerialPacketType::COMBAT_UPDATE:
//TODO: is this the best fit?
case SerialPacketType::COMBAT_ENTER_REQUEST:
case SerialPacketType::COMBAT_ENTER_RESPONSE:
case SerialPacketType::COMBAT_EXIT_REQUEST:
case SerialPacketType::COMBAT_EXIT_RESPONSE:
serializeCombat(static_cast<CombatPacket*>(packet), buffer);
break;
//enemy info
case SerialPacketType::ENEMY_NEW:
case SerialPacketType::ENEMY_DELETE:
case SerialPacketType::ENEMY_UPDATE:
case SerialPacketType::ENEMY_STATS_REQUEST:
case SerialPacketType::ENEMY_STATS_RESPONSE:
serializeEnemy(static_cast<EnemyPacket*>(packet), buffer);
break;
//region info
case SerialPacketType::REGION_REQUEST:
deserializeRegionFormat(static_cast<RegionPacket*>(packet), buffer);
break;
case SerialPacketType::REGION_CONTENT:
deserializeRegionContent(static_cast<RegionPacket*>(packet), buffer);
break;
//server info
case SerialPacketType::BROADCAST_RESPONSE:
deserializeServer(static_cast<ServerPacket*>(packet), buffer);
break;
}
}
+65
View File
@@ -0,0 +1,65 @@
/* Copyright: (c) Kayne Ruse 2014
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be
* appreciated but is not required.
*
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
*
* 3. This notice may not be removed or altered from any source
* distribution.
*/
#ifndef SERIALIZE_HPP_
#define SERIALIZE_HPP_
#include "serial_packet.hpp"
#include "region.hpp"
#include "statistics.hpp"
//Primary interface functions
void serializePacket(SerialPacketBase*, void* dest);
void deserializePacket(SerialPacketBase*, void* src);
void serializeType(SerialPacketBase*, void*);
void deserializeType(SerialPacketBase*, void*);
//utility functions, exposed
void serializeCharacter(CharacterPacket*, void*);
void serializeClient(ClientPacket*, void*);
void serializeCombat(CombatPacket*, void*);
void serializeEnemy(EnemyPacket*, void*);
void serializeRegionFormat(RegionPacket*, void*);
void serializeRegionContent(RegionPacket*, void*);
void serializeServer(ServerPacket*, void*);
void serializeStatistics(Statistics*, void*);
void deserializeCharacter(CharacterPacket*, void*);
void deserializeClient(ClientPacket*, void*);
void deserializeCombat(CombatPacket*, void*);
void deserializeEnemy(EnemyPacket*, void*);
void deserializeRegionFormat(RegionPacket*, void*);
void deserializeRegionContent(RegionPacket*, void*);
void deserializeServer(ServerPacket*, void*);
void deserializeStatistics(Statistics*, void*);
/* DOCS: Keep the PACKET_BUFFER_SIZE up to date
* DOCS: REGION_CONTENT is currently the largest type of packet, read more
* map content: REGION_WIDTH * REGION_HEIGHT * REGION_DEPTH * sizoeof(region::type_t)
* map format: sizeof(int) * 3
* metadata: sizeof(SerialPacket::Type)
*/
constexpr int PACKET_BUFFER_SIZE = REGION_WIDTH * REGION_HEIGHT * REGION_DEPTH * sizeof(Region::type_t) + sizeof(int) * 3 + sizeof(SerialPacketType);
#endif
@@ -0,0 +1,80 @@
/* Copyright: (c) Kayne Ruse 2014
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be
* appreciated but is not required.
*
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
*
* 3. This notice may not be removed or altered from any source
* distribution.
*/
#include "serial.hpp"
#include "serial_util.hpp"
void serializeCharacter(CharacterPacket* packet, void* buffer) {
SERIALIZE(buffer, &packet->type, sizeof(SerialPacketType));
//identify the character
SERIALIZE(buffer, &packet->characterIndex, sizeof(int));
SERIALIZE(buffer, &packet->handle, PACKET_STRING_SIZE);
SERIALIZE(buffer, &packet->avatar, PACKET_STRING_SIZE);
//the owner
SERIALIZE(buffer, &packet->accountIndex, sizeof(int));
//location
SERIALIZE(buffer, &packet->roomIndex, sizeof(int));
SERIALIZE(buffer, &packet->origin.x, sizeof(double));
SERIALIZE(buffer, &packet->origin.y, sizeof(double));
SERIALIZE(buffer, &packet->motion.x, sizeof(double));
SERIALIZE(buffer, &packet->motion.y, sizeof(double));
//stats structure
serializeStatistics(&packet->stats, buffer);
buffer = reinterpret_cast<char*>(buffer) + sizeof(Statistics);
//TODO: equipment
//TODO: items
//TODO: buffs
//TODO: debuffs
}
void deserializeCharacter(CharacterPacket* packet, void* buffer) {
DESERIALIZE(buffer, &packet->type, sizeof(SerialPacketType));
//identify the character
DESERIALIZE(buffer, &packet->characterIndex, sizeof(int));
DESERIALIZE(buffer, &packet->handle, PACKET_STRING_SIZE);
DESERIALIZE(buffer, &packet->avatar, PACKET_STRING_SIZE);
//the owner
DESERIALIZE(buffer, &packet->accountIndex, sizeof(int));
//location
DESERIALIZE(buffer, &packet->roomIndex, sizeof(int));
DESERIALIZE(buffer, &packet->origin.x, sizeof(double));
DESERIALIZE(buffer, &packet->origin.y, sizeof(double));
DESERIALIZE(buffer, &packet->motion.x, sizeof(double));
DESERIALIZE(buffer, &packet->motion.y, sizeof(double));
//stats structure
deserializeStatistics(&packet->stats, buffer);
buffer = reinterpret_cast<char*>(buffer) + sizeof(Statistics);
//TODO: equipment
//TODO: items
//TODO: buffs
//TODO: debuffs
}
+42
View File
@@ -0,0 +1,42 @@
/* Copyright: (c) Kayne Ruse 2014
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be
* appreciated but is not required.
*
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
*
* 3. This notice may not be removed or altered from any source
* distribution.
*/
#include "serial.hpp"
#include "serial_util.hpp"
void serializeClient(ClientPacket* packet, void* buffer) {
SERIALIZE(buffer, &packet->type, sizeof(SerialPacketType));
SERIALIZE(buffer, &packet->clientIndex, sizeof(int));
SERIALIZE(buffer, &packet->accountIndex, sizeof(int));
SERIALIZE(buffer, &packet->username, PACKET_STRING_SIZE);
// SERIALIZE(buffer, &packet->password, PACKET_STRING_SIZE);
}
void deserializeClient(ClientPacket* packet, void* buffer) {
DESERIALIZE(buffer, &packet->type, sizeof(SerialPacketType));
DESERIALIZE(buffer, &packet->clientIndex, sizeof(int));
DESERIALIZE(buffer, &packet->accountIndex, sizeof(int));
DESERIALIZE(buffer, &packet->username, PACKET_STRING_SIZE);
// DESERIALIZE(buffer, &packet->password, PACKET_STRING_SIZE);
}
+64
View File
@@ -0,0 +1,64 @@
/* Copyright: (c) Kayne Ruse 2014
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be
* appreciated but is not required.
*
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
*
* 3. This notice may not be removed or altered from any source
* distribution.
*/
#include "serial.hpp"
#include "serial_util.hpp"
void serializeCombat(CombatPacket* packet, void* buffer) {
SERIALIZE(buffer, &packet->type, sizeof(SerialPacketType));
//identify the combat instance
SERIALIZE(buffer, &packet->combatIndex, sizeof(int));
SERIALIZE(buffer, &packet->difficulty, sizeof(int));
SERIALIZE(buffer, &packet->terrainType, sizeof(CombatData::Terrain));
//combatants
SERIALIZE(buffer, &packet->characterArray, sizeof(int) * COMBAT_MAX_CHARACTERS);
SERIALIZE(buffer, &packet->enemyArray, sizeof(int) * COMBAT_MAX_ENEMIES);
//location
SERIALIZE(buffer, &packet->mapIndex, sizeof(int));
SERIALIZE(buffer, &packet->origin.x, sizeof(double));
SERIALIZE(buffer, &packet->origin.y, sizeof(double));
//TODO: rewards
}
void deserializeCombat(CombatPacket* packet, void* buffer) {
DESERIALIZE(buffer, &packet->type, sizeof(SerialPacketType));
//identify the combat instance
DESERIALIZE(buffer, &packet->combatIndex, sizeof(int));
DESERIALIZE(buffer, &packet->difficulty, sizeof(int));
DESERIALIZE(buffer, &packet->terrainType, sizeof(CombatData::Terrain));
//combatants
DESERIALIZE(buffer, &packet->characterArray, sizeof(int) * COMBAT_MAX_CHARACTERS);
DESERIALIZE(buffer, &packet->enemyArray, sizeof(int) * COMBAT_MAX_ENEMIES);
//location
DESERIALIZE(buffer, &packet->mapIndex, sizeof(int));
DESERIALIZE(buffer, &packet->origin.x, sizeof(double));
DESERIALIZE(buffer, &packet->origin.y, sizeof(double));
//TODO: rewards
}
+66
View File
@@ -0,0 +1,66 @@
/* Copyright: (c) Kayne Ruse 2014
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be
* appreciated but is not required.
*
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
*
* 3. This notice may not be removed or altered from any source
* distribution.
*/
#include "serial.hpp"
#include "serial_util.hpp"
void serializeEnemy(EnemyPacket* packet, void* buffer) {
SERIALIZE(buffer, &packet->type, sizeof(SerialPacketType));
//identify the enemy
SERIALIZE(buffer, &packet->enemyIndex, sizeof(int));
SERIALIZE(buffer, &packet->handle, PACKET_STRING_SIZE);
SERIALIZE(buffer, &packet->avatar, PACKET_STRING_SIZE);
//gameplay
//stats structure
serializeStatistics(&packet->stats, buffer);
buffer = reinterpret_cast<char*>(buffer) + sizeof(Statistics);
//TODO: equipment
//TODO: items
//TODO: buffs
//TODO: debuffs
//TODO: rewards
}
void deserializeEnemy(EnemyPacket* packet, void* buffer) {
DESERIALIZE(buffer, &packet->type, sizeof(SerialPacketType));
//identify the enemy
DESERIALIZE(buffer, &packet->enemyIndex, sizeof(int));
DESERIALIZE(buffer, &packet->handle, PACKET_STRING_SIZE);
DESERIALIZE(buffer, &packet->avatar, PACKET_STRING_SIZE);
//stats structure
deserializeStatistics(&packet->stats, buffer);
buffer = reinterpret_cast<char*>(buffer) + sizeof(Statistics);
//TODO: equipment
//TODO: items
//TODO: buffs
//TODO: debuffs
//TODO: rewards
}
+83
View File
@@ -0,0 +1,83 @@
/* Copyright: (c) Kayne Ruse 2014
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be
* appreciated but is not required.
*
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
*
* 3. This notice may not be removed or altered from any source
* distribution.
*/
#include "serial.hpp"
#include "serial_util.hpp"
void serializeRegionFormat(RegionPacket* packet, void* buffer) {
SERIALIZE(buffer, &packet->type, sizeof(SerialPacketType));
//format
SERIALIZE(buffer, &packet->roomIndex, sizeof(int));
SERIALIZE(buffer, &packet->x, sizeof(int));
SERIALIZE(buffer, &packet->y, sizeof(int));
}
void serializeRegionContent(RegionPacket* packet, void* buffer) {
SERIALIZE(buffer, &packet->type, sizeof(SerialPacketType));
//format
SERIALIZE(buffer, &packet->roomIndex, sizeof(int));
SERIALIZE(buffer, &packet->x, sizeof(int));
SERIALIZE(buffer, &packet->y, sizeof(int));
//content
for (register int i = 0; i < REGION_WIDTH; i++) {
for (register int j = 0; j < REGION_HEIGHT; j++) {
for (register int k = 0; k < REGION_DEPTH; k++) {
*reinterpret_cast<Region::type_t*>(buffer) = packet->region->GetTile(i, j, k);
buffer = reinterpret_cast<char*>(buffer) + sizeof(Region::type_t);
}
}
}
}
void deserializeRegionFormat(RegionPacket* packet, void* buffer) {
DESERIALIZE(buffer, &packet->type, sizeof(SerialPacketType));
//format
DESERIALIZE(buffer, &packet->roomIndex, sizeof(int));
DESERIALIZE(buffer, &packet->x, sizeof(int));
DESERIALIZE(buffer, &packet->y, sizeof(int));
}
void deserializeRegionContent(RegionPacket* packet, void* buffer) {
DESERIALIZE(buffer, &packet->type, sizeof(SerialPacketType));
//format
DESERIALIZE(buffer, &packet->roomIndex, sizeof(int));
DESERIALIZE(buffer, &packet->x, sizeof(int));
DESERIALIZE(buffer, &packet->y, sizeof(int));
//an object to work on
packet->region = new Region(packet->x, packet->y);
//content
for (register int i = 0; i < REGION_WIDTH; i++) {
for (register int j = 0; j < REGION_HEIGHT; j++) {
for (register int k = 0; k < REGION_DEPTH; k++) {
packet->region->SetTile(i, j, k, *reinterpret_cast<Region::type_t*>(buffer));
buffer = reinterpret_cast<char*>(buffer) + sizeof(Region::type_t);
}
}
}
}
+42
View File
@@ -0,0 +1,42 @@
/* Copyright: (c) Kayne Ruse 2014
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be
* appreciated but is not required.
*
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
*
* 3. This notice may not be removed or altered from any source
* distribution.
*/
#include "serial.hpp"
#include "serial_util.hpp"
void serializeServer(ServerPacket* packet, void* buffer) {
SERIALIZE(buffer, &packet->type, sizeof(SerialPacketType));
//identify the server
SERIALIZE(buffer, &packet->name, PACKET_STRING_SIZE);
SERIALIZE(buffer, &packet->playerCount, sizeof(int));
SERIALIZE(buffer, &packet->version, sizeof(int));
}
void deserializeServer(ServerPacket* packet, void* buffer) {
DESERIALIZE(buffer, &packet->type, sizeof(SerialPacketType));
//identify the server
DESERIALIZE(buffer, &packet->name, PACKET_STRING_SIZE);
DESERIALIZE(buffer, &packet->playerCount, sizeof(int));
DESERIALIZE(buffer, &packet->version, sizeof(int));
}
@@ -0,0 +1,65 @@
/* Copyright: (c) Kayne Ruse 2014
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be
* appreciated but is not required.
*
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
*
* 3. This notice may not be removed or altered from any source
* distribution.
*/
#include "serial.hpp"
#include "serial_util.hpp"
void serializeStatistics(Statistics* stats, void* buffer) {
//integers
SERIALIZE(buffer, &stats->level, sizeof(int));
SERIALIZE(buffer, &stats->exp, sizeof(int));
SERIALIZE(buffer, &stats->maxHP, sizeof(int));
SERIALIZE(buffer, &stats->health, sizeof(int));
SERIALIZE(buffer, &stats->maxMP, sizeof(int));
SERIALIZE(buffer, &stats->mana, sizeof(int));
SERIALIZE(buffer, &stats->attack, sizeof(int));
SERIALIZE(buffer, &stats->defence, sizeof(int));
SERIALIZE(buffer, &stats->intelligence, sizeof(int));
SERIALIZE(buffer, &stats->resistance, sizeof(int));
SERIALIZE(buffer, &stats->speed, sizeof(int));
//floats
SERIALIZE(buffer, &stats->accuracy, sizeof(float));
SERIALIZE(buffer, &stats->evasion, sizeof(float));
SERIALIZE(buffer, &stats->luck, sizeof(float));
}
void deserializeStatistics(Statistics* stats, void* buffer) {
//integers
DESERIALIZE(buffer, &stats->level, sizeof(int));
DESERIALIZE(buffer, &stats->exp, sizeof(int));
DESERIALIZE(buffer, &stats->maxHP, sizeof(int));
DESERIALIZE(buffer, &stats->health, sizeof(int));
DESERIALIZE(buffer, &stats->maxMP, sizeof(int));
DESERIALIZE(buffer, &stats->mana, sizeof(int));
DESERIALIZE(buffer, &stats->attack, sizeof(int));
DESERIALIZE(buffer, &stats->defence, sizeof(int));
DESERIALIZE(buffer, &stats->intelligence, sizeof(int));
DESERIALIZE(buffer, &stats->resistance, sizeof(int));
DESERIALIZE(buffer, &stats->speed, sizeof(int));
//floats
DESERIALIZE(buffer, &stats->accuracy, sizeof(float));
DESERIALIZE(buffer, &stats->evasion, sizeof(float));
DESERIALIZE(buffer, &stats->luck, sizeof(float));
}
+31
View File
@@ -0,0 +1,31 @@
/* Copyright: (c) Kayne Ruse 2014
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be
* appreciated but is not required.
*
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
*
* 3. This notice may not be removed or altered from any source
* distribution.
*/
#ifndef SERIALIZEUTIL_HPP_
#define SERIALIZEUTIL_HPP_
#include <cstring>
//NOTE: The strange assignments here used in order to move the void* parameter
#define SERIALIZE(buffer, data, size) memcpy(buffer, data, size); buffer = reinterpret_cast<char*>(buffer) + size;
#define DESERIALIZE(buffer, data, size) memcpy(data, buffer, size); buffer = reinterpret_cast<char*>(buffer) + size;
#endif
+224
View File
@@ -0,0 +1,224 @@
/* Copyright: (c) Kayne Ruse 2013, 2014
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be
* appreciated but is not required.
*
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
*
* 3. This notice may not be removed or altered from any source
* distribution.
*/
#include "udp_network_utility.hpp"
#include "serial.hpp"
#include <stdexcept>
//DOCS: memset() is used before sending a packet to remove old data; you don't want to send sensitive data over the network
//NOTE: don't confuse SerialPacket with UDPpacket
void UDPNetworkUtility::Open(int port) {
socket = SDLNet_UDP_Open(port);
packet = SDLNet_AllocPacket(PACKET_BUFFER_SIZE);
if (!socket || !packet) {
Close();
throw(std::runtime_error("Failed to open UDPNetworkUtility"));
}
}
void UDPNetworkUtility::Close() {
SDLNet_UDP_Close(socket);
SDLNet_FreePacket(packet);
socket = nullptr;
packet = nullptr;
}
//-------------------------
//bind to a channel
//-------------------------
int UDPNetworkUtility::Bind(const char* ip, int port, int channel) {
IPaddress add;
if (SDLNet_ResolveHost(&add, ip, port) == -1) {
throw(std::runtime_error("Failed to resolve a host"));
}
return Bind(&add, channel);
}
int UDPNetworkUtility::Bind(IPaddress* add, int channel) {
int ret = SDLNet_UDP_Bind(socket, channel, add);
if (ret < 0) {
throw(std::runtime_error("Failed to bind to a channel"));
}
return ret;
}
void UDPNetworkUtility::Unbind(int channel) {
SDLNet_UDP_Unbind(socket, channel);
}
//-------------------------
//send a buffer
//-------------------------
int UDPNetworkUtility::SendTo(const char* ip, int port, void* data, int len) {
IPaddress add;
if (SDLNet_ResolveHost(&add, ip, port) == -1) {
throw(std::runtime_error("Failed to resolve a host"));
}
SendTo(&add, data, len);
}
int UDPNetworkUtility::SendTo(IPaddress* add, void* data, int len) {
if (len > packet->maxlen) {
throw(std::runtime_error("The buffer is to large for the UDPpacket"));
}
memset(packet->data, 0, packet->maxlen);
memcpy(packet->data, data, len);
packet->len = len;
packet->address = *add;
int ret = SDLNet_UDP_Send(socket, -1, packet);
if (ret <= 0) {
throw(std::runtime_error("Failed to send a packet"));
}
return ret;
}
int UDPNetworkUtility::SendTo(int channel, void* data, int len) {
if (len > packet->maxlen) {
throw(std::runtime_error("The buffer is to large for the UDPpacket"));
}
memset(packet->data, 0, packet->maxlen);
memcpy(packet->data, data, len);
packet->len = len;
int ret = SDLNet_UDP_Send(socket, channel, packet);
if (ret <= 0) {
throw(std::runtime_error("Failed to send a packet"));
}
return ret;
}
int UDPNetworkUtility::SendToAllChannels(void* data, int len) {
if (len > packet->maxlen) {
throw(std::runtime_error("The buffer is to large for the UDPpacket"));
}
memset(packet->data, 0, packet->maxlen);
memcpy(packet->data, data, len);
packet->len = len;
int sent = 0;
//send to all bound channels
for (int i = 0; i < SDLNET_MAX_UDPCHANNELS; i++) {
if (SDLNet_UDP_GetPeerAddress(socket, i)) {
sent += SDLNet_UDP_Send(socket, i, packet);
}
}
return sent;
}
//TODO: put a void* and int* parameter list here
int UDPNetworkUtility::Receive() {
memset(packet->data, 0, packet->maxlen);
int ret = SDLNet_UDP_Recv(socket, packet);
if (ret < 0) {
throw(std::runtime_error("Unknown network error occured"));
}
return ret;
}
//-------------------------
//send a SerialPacket
//-------------------------
int UDPNetworkUtility::SendTo(const char* ip, int port, SerialPacket* serialPacket) {
IPaddress add;
if (SDLNet_ResolveHost(&add, ip, port) == -1) {
throw(std::runtime_error("Failed to resolve a host"));
}
SendTo(&add, serialPacket);
}
int UDPNetworkUtility::SendTo(IPaddress* add, SerialPacket* serialPacket) {
memset(packet->data, 0, packet->maxlen);
serializePacket(serialPacket, packet->data);
packet->len = PACKET_BUFFER_SIZE;
packet->address = *add;
int ret = SDLNet_UDP_Send(socket, -1, packet);
if (ret <= 0) {
throw(std::runtime_error("Failed to send a packet"));
}
return ret;
}
int UDPNetworkUtility::SendTo(int channel, SerialPacket* serialPacket) {
memset(packet->data, 0, packet->maxlen);
serializePacket(serialPacket, packet->data);
packet->len = PACKET_BUFFER_SIZE;
int ret = SDLNet_UDP_Send(socket, channel, packet);
if (ret <= 0) {
throw(std::runtime_error("Failed to send a packet"));
}
return ret;
}
int UDPNetworkUtility::SendToAllChannels(SerialPacket* serialPacket) {
memset(packet->data, 0, packet->maxlen);
serializePacket(serialPacket, packet->data);
packet->len = PACKET_BUFFER_SIZE;
int sent = 0;
//send to all bound channels
for (int i = 0; i < SDLNET_MAX_UDPCHANNELS; i++) {
if (SDLNet_UDP_GetPeerAddress(socket, i)) {
sent += SDLNet_UDP_Send(socket, i, packet);
}
}
return sent;
}
int UDPNetworkUtility::Receive(SerialPacket* serialPacket) {
memset(packet->data, 0, packet->maxlen);
int ret = SDLNet_UDP_Recv(socket, packet);
deserializePacket(serialPacket, packet->data);
serialPacket->srcAddress = packet->address;
if (ret < 0) {
throw(std::runtime_error("Unknown network error occured"));
}
return ret;
}
+72
View File
@@ -0,0 +1,72 @@
/* Copyright: (c) Kayne Ruse 2013, 2014
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be
* appreciated but is not required.
*
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
*
* 3. This notice may not be removed or altered from any source
* distribution.
*/
#ifndef UDPNETWORKUTILITY_HPP_
#define UDPNETWORKUTILITY_HPP_
#include "SDL/SDL_net.h"
#include "serial_packet.hpp"
class UDPNetworkUtility {
public:
UDPNetworkUtility() = default;
~UDPNetworkUtility() = default;
void Open(int port);
void Close();
//bind to a channel
int Bind(const char* ip, int port, int channel = -1);
int Bind(IPaddress* add, int channel = -1);
void Unbind(int channel);
IPaddress* GetIPAddress(int channel) {
return SDLNet_UDP_GetPeerAddress(socket, channel);
}
//send a buffer
int SendTo(const char* ip, int port, void* data, int len);
int SendTo(IPaddress* add, void* data, int len);
int SendTo(int channel, void* data, int len);
int SendToAllChannels(void* data, int len);
int Receive();
//send a SerialPacket
int SendTo(const char* ip, int port, SerialPacket* serialPacket);
int SendTo(IPaddress* add, SerialPacket* serialPacket);
int SendTo(int channel, SerialPacket* serialPacket);
int SendToAllChannels(SerialPacket* serialPacket);
int Receive(SerialPacket* serialPacket);
//accessors
UDPpacket* GetPacket() const {
return packet;
}
UDPsocket GetSocket() const {
return socket;
}
private:
UDPsocket socket = nullptr;
UDPpacket* packet = nullptr;
};
#endif
+81
View File
@@ -0,0 +1,81 @@
/* Copyright: (c) Kayne Ruse 2013, 2014
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be
* appreciated but is not required.
*
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
*
* 3. This notice may not be removed or altered from any source
* distribution.
*/
#include "button.hpp"
#include <stdexcept>
Button::State Button::MouseMotion(SDL_MouseMotionEvent const& motion) {
return CalcState(motion.x, motion.y, motion.state & SDL_BUTTON_LMASK);
}
Button::State Button::MouseButtonDown(SDL_MouseButtonEvent const& button) {
if (button.button == SDL_BUTTON_LEFT) {
return CalcState(button.x, button.y, true);
}
return state;
}
Button::State Button::MouseButtonUp(SDL_MouseButtonEvent const& button) {
if (button.button == SDL_BUTTON_LEFT) {
return CalcState(button.x, button.y, false);
}
return state;
}
void Button::DrawTo(SDL_Surface* const dest) {
if (!image || !font) {
throw(std::runtime_error("Surface not set for Button"));
}
image->SetClipY(state * image->GetClipH());
image->DrawTo(dest, x, y);
font->DrawStringTo(text, dest, textX + x, textY + y);
}
std::string Button::SetText(std::string t) {
if (!image || !font) {
throw(std::runtime_error("Surface not set for Button"));
}
//one line, cache the position
text = t;
textX = (image->GetClipW() / 2) - (font->GetCharW() * text.size() / 2);
textY = (image->GetClipH() / 2) - (font->GetCharH() / 2);
return text;
}
Button::State Button::CalcState(Sint16 i, Sint16 j, bool leftPressed) {
if (!image || !font) {
throw(std::runtime_error("Surface not set for Button"));
}
//if out of bounds
if (i < x || i >= (x + image->GetClipW()) ||
j < y || j >= (y + image->GetClipH())
) {
return state = State::NORMAL;
}
if (leftPressed) {
return state = State::PRESSED;
}
else {
return state = State::HOVER;
}
}
+94
View File
@@ -0,0 +1,94 @@
/* Copyright: (c) Kayne Ruse 2013, 2014
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be
* appreciated but is not required.
*
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
*
* 3. This notice may not be removed or altered from any source
* distribution.
*/
#ifndef BUTTON_HPP_
#define BUTTON_HPP_
#include "image.hpp"
#include "raster_font.hpp"
#include <string>
/* 3-phases, no toggle, centred text
* This class uses the size of the provided image as its bounds. Also,
* The provided image should be formatted correctly.
*
* The button's image should be divided into 3 sections virtucally,
* which act as the different button images. The clip width & height of the
* Image should be set manually, and the height should be 1/3 of the total
* graphical data.
*/
class Button {
public:
enum State {
NORMAL = 0, HOVER = 1, PRESSED = 2
};
Button() = default;
~Button() = default;
//handle input
State MouseMotion(SDL_MouseMotionEvent const&);
State MouseButtonDown(SDL_MouseButtonEvent const&);
State MouseButtonUp(SDL_MouseButtonEvent const&);
//yet another draw function
void DrawTo(SDL_Surface* const);
//accessors and mutators
Image* SetImage(Image* const ptr) { return image = ptr; }
Image* GetImage() { return image; }
RasterFont* SetFont(RasterFont* const ptr) { return font = ptr; }
RasterFont* GetFont() { return font; }
Sint16 SetX(Sint16 i) { return x = i; }
Sint16 SetY(Sint16 i) { return y = i; }
Sint16 GetX() const { return x; }
Sint16 GetY() const { return y; }
Sint16 SetTextX(Sint16 i) { return textX = i; }
Sint16 SetTextY(Sint16 i) { return textY = i; }
Sint16 GetTextX() const { return textX; }
Sint16 GetTextY() const { return textY; }
State SetState(State s) { return state = s; }
State GetState() const { return state; }
std::string SetText(std::string);
std::string GetText() const { return text; }
private:
State CalcState(Sint16 x, Sint16 y, bool leftPressed);
//point to the provided external objects
Image* image = nullptr;
RasterFont* font = nullptr;
//positions
Sint16 x = 0, y = 0;
Sint16 textX = 0, textY = 0;
//
State state = State::NORMAL;
std::string text;
};
#endif
+37
View File
@@ -0,0 +1,37 @@
#config
INCLUDES+=. ../graphics
LIBS+=
CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES))
#source
CXXSRC=$(wildcard *.cpp)
#objects
OBJDIR=obj
OBJ+=$(addprefix $(OBJDIR)/,$(CXXSRC:.cpp=.o))
#output
OUTDIR=../..
OUT=$(addprefix $(OUTDIR)/,libcommon.a)
#targets
all: $(OBJ) $(OUT)
ar -crs $(OUT) $(OBJ)
$(OBJ): | $(OBJDIR)
$(OUT): | $(OUTDIR)
$(OBJDIR):
mkdir $(OBJDIR)
$(OUTDIR):
mkdir $(OUTDIR)
$(OBJDIR)/%.o: %.cpp
$(CXX) $(CXXFLAGS) -c -o $@ $<
clean:
$(RM) *.o *.a *.exe
rebuild: clean all
+139
View File
@@ -0,0 +1,139 @@
/* Copyright: (c) Kayne Ruse 2013, 2014
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be
* appreciated but is not required.
*
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
*
* 3. This notice may not be removed or altered from any source
* distribution.
*/
#include "menu_bar.hpp"
#include <stdexcept>
#include <sstream>
void MenuBar::DrawTo(SDL_Surface* const dest) {
for (auto& i : entries) {
i.DrawTo(dest);
}
}
void MenuBar::MouseMotion(SDL_MouseMotionEvent const& motion) {
for (auto& i : entries) {
i.MouseMotion(motion);
}
}
void MenuBar::MouseButtonDown(SDL_MouseButtonEvent const& button) {
for (auto& i : entries) {
i.MouseButtonDown(button);
}
}
void MenuBar::MouseButtonUp(SDL_MouseButtonEvent const& button, int* entry, int* butt) {
*entry = *butt = -1;
int ret = -1;
for (auto& i : entries) {
ret = i.MouseButtonUp(button);
if (ret != -1) {
*entry = (&i - entries.data());
*butt = ret;
}
}
}
void MenuBar::SetEntries(std::vector<std::vector<std::string>> info) {
if (!image || !font) {
throw(std::runtime_error("Surfaces not loaded into the menu bar"));
}
entries.clear();
for (int i = 0; i < info.size(); i++) {
//create the entry & the main button
entries.push_back(MenuBarEntry());
entries[i].mainButton.SetImage(image);
entries[i].mainButton.SetFont(font);
entries[i].mainButton.SetText(info[i][0]);
entries[i].mainButton.SetX(i * image->GetClipW());
entries[i].mainButton.SetY(0);
for (int j = 0; j < info[i].size()-1; j++) {
//create each drop button in this entry
entries[i].dropButtons.push_back(Button());
entries[i].dropButtons[j].SetImage(image);
entries[i].dropButtons[j].SetFont(font);
entries[i].dropButtons[j].SetText(info[i][j+1]);
entries[i].dropButtons[j].SetX(i * image->GetClipW());
entries[i].dropButtons[j].SetY((j+1) * image->GetClipH());
}
}
}
void MenuBar::MenuBarEntry::DrawTo(SDL_Surface* const dest) {
//only draw the dropButtons in the user has this menu open
mainButton.DrawTo(dest);
if (!open) {
return;
}
for (auto& i : dropButtons) {
i.DrawTo(dest);
}
}
void MenuBar::MenuBarEntry::MouseMotion(SDL_MouseMotionEvent const& motion) {
//open the menu
bool o = mainButton.MouseMotion(motion) == Button::State::PRESSED;
if (!(open |= o)) {
return;
}
for (auto& i : dropButtons) {
//dragging down the menu
o |= i.MouseMotion(motion) == Button::State::PRESSED;
}
open = o;
}
void MenuBar::MenuBarEntry::MouseButtonDown(SDL_MouseButtonEvent const& button) {
//open the menu
if (!(open = mainButton.MouseButtonDown(button) == Button::State::PRESSED)) {
return;
}
//update the others anyway
for (auto& i : dropButtons) {
i.MouseButtonDown(button);
}
}
int MenuBar::MenuBarEntry::MouseButtonUp(SDL_MouseButtonEvent const& button) {
int ret = -1;
mainButton.MouseButtonUp(button);
for (auto& i : dropButtons) {
//the user just released this button
if (i.GetState() != i.MouseButtonUp(button) && i.GetState() == Button::State::HOVER && open) {
//get this button's index
ret = (&i - dropButtons.data());
}
}
open = false;
return ret;
}
+91
View File
@@ -0,0 +1,91 @@
/* Copyright: (c) Kayne Ruse 2013, 2014
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be
* appreciated but is not required.
*
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
*
* 3. This notice may not be removed or altered from any source
* distribution.
*/
#ifndef MENUBAR_HPP_
#define MENUBAR_HPP_
#include "image.hpp"
#include "raster_font.hpp"
#include "button.hpp"
#include <string>
#include <vector>
/* I've redesigned this so that the contents of the menu bar can't change during run time.
* This is more restrictive but I'm focusing on getting this working first.
* The Image and Font pointers must be set before the text data is entered.
*
* This class needs a rewrite.
*/
class MenuBar {
public:
MenuBar() = default;
~MenuBar() = default;
//yet another draw function
void DrawTo(SDL_Surface* const dest);
//user inputs
void MouseMotion(SDL_MouseMotionEvent const&);
void MouseButtonDown(SDL_MouseButtonEvent const&);
void MouseButtonUp(SDL_MouseButtonEvent const&, int* entry, int* button);
//manage the entries & buttons
void SetEntries(std::vector<std::vector<std::string>> info);
void ClearEntries() { entries.clear(); }
//Accessors and mutators
Image* SetImage(Image* const ptr) { return image = ptr; }
Image* GetImage() { return image; }
RasterFont* SetFont(RasterFont* const ptr) { return font = ptr; }
RasterFont* GetFont() { return font; }
private:
class MenuBarEntry;
std::vector<MenuBarEntry> entries;
Image* image = nullptr;
RasterFont* font = nullptr;
};
class MenuBar::MenuBarEntry {
public:
MenuBarEntry() = default;
~MenuBarEntry() = default;
void DrawTo(SDL_Surface* const dest);
void MouseMotion(SDL_MouseMotionEvent const&);
void MouseButtonDown(SDL_MouseButtonEvent const&);
int MouseButtonUp(SDL_MouseButtonEvent const&);
private:
Button mainButton;
std::vector<Button> dropButtons;
bool open = false;
friend class MenuBar;
};
#endif
+60
View File
@@ -0,0 +1,60 @@
/* Copyright: (c) Kayne Ruse 2013, 2014
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be
* appreciated but is not required.
*
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
*
* 3. This notice may not be removed or altered from any source
* distribution.
*/
#include "raster_font.hpp"
#include <stdexcept>
/* It might be more efficient to render to a different surface (like an Image)
* rather than calling this function with all of it's '%' and '/'.
*/
void RasterFont::DrawStringTo(std::string s, SDL_Surface* const dest, Sint16 x, Sint16 y) {
if (!image.GetSurface()) {
throw(std::runtime_error("RasterFont not loaded"));
}
const Uint16 w = image.GetClipW();
const Uint16 h = image.GetClipH();
for (int i = 0; i < s.size(); i++) {
image.SetClipX(s[i] % 16 * w);
image.SetClipY(s[i] / 16 * h);
image.DrawTo(dest, x + i * w, y);
}
}
/* Note: This class can only take a raster font with 16*16 characters, and the
* indevidual characters must have the same dimensions. Overall this class is too
* restrictive; I suggest using a 3rd party library.
*/
SDL_Surface* RasterFont::LoadSurface(std::string fname) {
image.LoadSurface(fname);
image.SetClipW(image.GetSurface()->w/16);
image.SetClipH(image.GetSurface()->h/16);
return image.GetSurface();
}
SDL_Surface* RasterFont::SetSurface(SDL_Surface* p) {
image.SetSurface(p);
image.SetClipW(image.GetSurface()->w/16);
image.SetClipH(image.GetSurface()->h/16);
return image.GetSurface();
}
+54
View File
@@ -0,0 +1,54 @@
/* Copyright: (c) Kayne Ruse 2013, 2014
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be
* appreciated but is not required.
*
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
*
* 3. This notice may not be removed or altered from any source
* distribution.
*/
#ifndef RASTERFONT_HPP_
#define RASTERFONT_HPP_
#include "image.hpp"
class RasterFont {
public:
RasterFont() = default;
RasterFont(RasterFont const& rhs) { *this = rhs; }
RasterFont(RasterFont&& rhs) { *this = std::move(rhs); }
RasterFont(std::string fname) { LoadSurface(fname); }
RasterFont(SDL_Surface* p) { SetSurface(p); }
~RasterFont() = default;
RasterFont& operator=(RasterFont const& rhs) { image = rhs.image; }
RasterFont& operator=(RasterFont&& rhs) { image = std::move(rhs.image); }
void DrawStringTo(std::string, SDL_Surface* const, Sint16 x, Sint16 y);
//Accessors and Mutators
SDL_Surface* LoadSurface(std::string);
SDL_Surface* SetSurface(SDL_Surface*);
SDL_Surface* GetSurface() const { return image.GetSurface(); }
void FreeSurface() { image.FreeSurface(); }
Uint16 GetCharW() const { return image.GetClipW(); }
Uint16 GetCharH() const { return image.GetClipH(); }
private:
Image image;
};
#endif
+40
View File
@@ -0,0 +1,40 @@
/* Copyright: (c) Kayne Ruse 2014
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be
* appreciated but is not required.
*
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
*
* 3. This notice may not be removed or altered from any source
* distribution.
*/
#include "check_bounds.hpp"
bool checkPoint(Vector2 const& origin, Vector2 const& bound, Vector2 const& point) {
return !(
point.x < origin.x ||
point.y < origin.y ||
point.x >= origin.x + bound.x ||
point.y >= origin.y + bound.y
);
}
bool checkOverlap(Vector2 const& originOne, Vector2 const& boundOne, Vector2 const& originTwo, Vector2 const& boundTwo) {
return !(
originOne.x >= originTwo.x + boundTwo.x ||
originOne.x + boundOne.x >= originTwo.x ||
originOne.y >= originTwo.y + boundTwo.y ||
originOne.y + boundOne.y >= originTwo.y
);
}
@@ -19,19 +19,12 @@
* 3. This notice may not be removed or altered from any source
* distribution.
*/
#ifndef MATHS_HPP_
#define MATHS_HPP_
#ifndef CHECKBOUNDS_HPP_
#define CHECKBOUNDS_HPP_
#include "vector2.hpp"
//param: 0 to 1 inclusive
double curve(double);
bool checkPoint(Vector2 const& origin, Vector2 const& bound, Vector2 const& point);
bool checkOverlap(Vector2 const& originOne, Vector2 const& boundOne, Vector2 const& originTwo, Vector2 const& boundTwo);
//snap x to a grid of base
double snap(double x, double base);
int snap(int x, int base);
//vector dot product
double scalarProduct(Vector2, Vector2);
#endif
#endif
+105
View File
@@ -0,0 +1,105 @@
/* Copyright: (c) Kayne Ruse 2013, 2014
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be
* appreciated but is not required.
*
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
*
* 3. This notice may not be removed or altered from any source
* distribution.
*/
#include "config_utility.hpp"
#include <cstdlib>
#include <fstream>
#include <stdexcept>
using namespace std;
void ConfigUtility::Load(string fname) {
ifstream is(fname);
if (!is.is_open()) {
throw(runtime_error("Failed to open config file"));
}
string key, val;
for (;;) { //forever
//eat whitespace
while(isspace(is.peek()))
is.ignore();
//end of file
if (is.eof())
break;
//skip comment lines
if (is.peek() == '#') {
while(is.peek() != '\n' && !is.eof()) {
is.ignore();
}
continue;
}
//read in the pair
getline(is, key,'=');
getline(is, val);
//trim the strings at the start & end
while(key.size() && isspace(*key.begin())) key.erase(0, 1);
while(val.size() && isspace(*val.begin())) val.erase(0, 1);
while(key.size() && isspace(*(key.end()-1))) key.erase(key.end() - 1);
while(val.size() && isspace(*(val.end()-1))) val.erase(val.end() - 1);
//allow empty/wiped values
if (key.size() == 0) {
continue;
}
//save the pair
table[key] = val;
}
is.close();
}
std::string& ConfigUtility::String(std::string s) {
return table[s];
}
int ConfigUtility::Integer(std::string s) {
std::map<std::string, std::string>::iterator it = table.find(s);
if (it == table.end()) {
return 0;
}
return atoi(it->second.c_str());
}
double ConfigUtility::Double(std::string s) {
std::map<std::string, std::string>::iterator it = table.find(s);
if (it == table.end()) {
return 0.0;
}
return atof(it->second.c_str());
}
bool ConfigUtility::Boolean(std::string s) {
std::map<std::string, std::string>::iterator it = table.find(s);
if (it == table.end()) {
return false;
}
return it->second == "true";
}
+60
View File
@@ -0,0 +1,60 @@
/* Copyright: (c) Kayne Ruse 2013, 2014
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be
* appreciated but is not required.
*
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
*
* 3. This notice may not be removed or altered from any source
* distribution.
*/
#ifndef CONFIGUTILITY_HPP_
#define CONFIGUTILITY_HPP_
#include <map>
#include <string>
class ConfigUtility {
public:
ConfigUtility() = default;
ConfigUtility(std::string s) { Load(s); }
void Load(std::string fname);
//convert to a type
std::string& String(std::string);
int Integer(std::string);
double Double(std::string);
bool Boolean(std::string);
//shorthand
std::string& operator[](std::string s) {
return String(s);
}
int Int(std::string s) {
return Integer(s);
}
bool Bool(std::string s) {
return Boolean(s);
}
//OO breaker
std::map<std::string, std::string>* GetMap() {
return &table;
}
private:
std::map<std::string, std::string> table;
};
#endif
+48
View File
@@ -0,0 +1,48 @@
/* Copyright: (c) Kayne Ruse 2014
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be
* appreciated but is not required.
*
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
*
* 3. This notice may not be removed or altered from any source
* distribution.
*/
#ifndef FRAMERATE_HPP_
#define FRAMERATE_HPP_
#include <chrono>
class FrameRate {
public:
typedef std::chrono::high_resolution_clock Clock;
FrameRate() = default;
int Calculate() {
frameCount++;
if (Clock::now() - tick >= std::chrono::duration<int>(1)) {
lastFrameRate = frameCount;
frameCount = 0;
tick = Clock::now();
}
return lastFrameRate;
}
int GetFrameRate() { return lastFrameRate; }
private:
int frameCount = 0;
int lastFrameRate = 0;
Clock::time_point tick = Clock::now();
};
#endif
+1 -1
View File
@@ -11,7 +11,7 @@ OBJDIR=obj
OBJ+=$(addprefix $(OBJDIR)/,$(CXXSRC:.cpp=.o))
#output
OUTDIR=..
OUTDIR=../..
OUT=$(addprefix $(OUTDIR)/,libcommon.a)
#targets
+50
View File
@@ -0,0 +1,50 @@
/* Copyright: (c) Kayne Ruse 2014
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be
* appreciated but is not required.
*
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
*
* 3. This notice may not be removed or altered from any source
* distribution.
*/
#include "sql_utility.hpp"
#include "utility.hpp"
#include <stdexcept>
#include <fstream>
#include <cstdlib>
int runSQLScript(sqlite3* db, std::string fname, int (*callback)(void*,int,char**,char**), void* argPtr) {
//load the file into a string
std::ifstream is(fname);
if (!is.is_open()) {
return -1;
}
std::string script;
getline(is, script, '\0');
is.close();
//run the SQL loaded from the file
char* errmsg = nullptr;
int ret = sqlite3_exec(db, script.c_str(), callback, argPtr, &errmsg);
if (ret != SQLITE_OK) {
//handle any errors received from the SQL
std::runtime_error e(std::string() + "SQL Script Error " + to_string_custom(ret) + ": " + errmsg);
free(errmsg);
throw(e);
}
return ret;
}
+31
View File
@@ -0,0 +1,31 @@
/* Copyright: (c) Kayne Ruse 2014
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be
* appreciated but is not required.
*
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
*
* 3. This notice may not be removed or altered from any source
* distribution.
*/
#ifndef SERVERUTILITY_HPP_
#define SERVERUTILITY_HPP_
#include "sqlite3/sqlite3.h"
#include <string>
int runSQLScript(sqlite3* db, std::string fname, int (*callback)(void*,int,char**,char**) = nullptr, void* argPtr = nullptr);
#endif
+59
View File
@@ -0,0 +1,59 @@
/* Copyright: (c) Kayne Ruse 2013, 2014
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be
* appreciated but is not required.
*
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
*
* 3. This notice may not be removed or altered from any source
* distribution.
*/
#include "utility.hpp"
#include <algorithm>
int snapToBase(int base, int x) {
//snap to a grid
if (x < 0) {
++x;
return x / base * base - base;
}
return x / base * base;
}
std::string truncatePath(std::string pathname) {
return std::string(
std::find_if(
pathname.rbegin(),
pathname.rend(),
[](char ch) -> bool {
//windows only
return ch == '/' || ch == '\\';
// //unix only
// return ch == '/';
}).base(),
pathname.end());
}
std::string to_string_custom(int i) {
char buffer[20];
snprintf(buffer, 20, "%d", i);
return std::string(buffer);
}
int to_integer_custom(std::string s) {
int ret = 0;
sscanf(s.c_str(), "%d", &ret);
return ret;
}
+35
View File
@@ -0,0 +1,35 @@
/* Copyright: (c) Kayne Ruse 2013, 2014
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be
* appreciated but is not required.
*
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
*
* 3. This notice may not be removed or altered from any source
* distribution.
*/
#ifndef UTILITY_HPP_
#define UTILITY_HPP_
#include <string>
int snapToBase(int base, int x);
std::string truncatePath(std::string pathname);
//fixing known bugs in g++
std::string to_string_custom(int i);
int to_integer_custom(std::string);
#endif
@@ -41,11 +41,6 @@ public:
double SquaredLength() const {
return x*x+y*y;
}
void Normalize() {
double l = Length();
x /= l;
y /= l;
}
//Arithmetic operators
Vector2 operator+(Vector2 v) const {
@@ -102,6 +97,15 @@ public:
template<typename T> bool operator!=(T t) { return (x != t || y != t); }
};
//non-member templates (flip the order)
template<typename T> Vector2 operator+(T t, Vector2 v) { return v + t; }
template<typename T> Vector2 operator-(T t, Vector2 v) { return v - t; }
template<typename T> Vector2 operator*(T t, Vector2 v) { return v * t; }
template<typename T> Vector2 operator/(T t, Vector2 v) { return v / t; }
template<typename T> bool operator==(T t, Vector2 v) { return v == t; }
template<typename T> bool operator!=(T t, Vector2 v) { return v != t; }
//This is explicitly a POD
static_assert(std::is_pod<Vector2>::value, "Vector2 is not a POD");
+3 -3
View File
@@ -10,9 +10,9 @@ export
OUTDIR=out
all: $(OUTDIR)
$(MAKE) -C utils
$(MAKE) -C mapgen
$(MAKE) -C src
$(MAKE) -C common
$(MAKE) -C server
$(MAKE) -C client
$(OUTDIR):
mkdir $(OUTDIR)
-120
View File
@@ -1,120 +0,0 @@
/* Copyright: (c) Kayne Ruse 2014
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be
* appreciated but is not required.
*
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
*
* 3. This notice may not be removed or altered from any source
* distribution.
*/
#include "map_generator.hpp"
#include "vector2.hpp"
#include <cmath>
//-------------------------
//Utility functions
//-------------------------
//snap to a grid (floating point version)
static double snap(double x, double base) {
return floor(x / base) * base;
}
//A.K.A.: the dot product
static double scalarProduct(Vector2 lhs, Vector2 rhs) {
return lhs.x * rhs.x + lhs.y * rhs.y;
}
//curved interpolation
static double curve(double x) {
//param: 0 to 1 inclusive
return 3.0 * pow(x, 2.0) - 2.0 * pow(x, 3.0);
}
//fix the overflow
static double curl(double x) {
if (x > 1.0) {
return -curl(x-1) +1;
}
if (x < 0.0) {
return curl(-x);
}
return x;
}
static double cut(double x) {
if (x > 1.0) {
return 1.0;
}
if (x < 0.0) {
return 0.0;
}
return x;
}
//-------------------------
//Public methods
//-------------------------
Vector2 MapGenerator::RawNoise(Vector2 const& gridPoint) {
double angle = rng(gridPoint.x * 0xffff + gridPoint.y);
Vector2 v = {cos(angle), sin(angle)};
v.Normalize();
return v;
}
double MapGenerator::Influence(Vector2 const& gridPoint, Vector2 const& queryPoint, double width, double height) {
//note: inverting the distance here, so the smaller the distance the more influence it has
Vector2 distance = queryPoint - gridPoint;
Vector2 inverted = {width - distance.x, height - distance.y};
double ret = scalarProduct(RawNoise(gridPoint), inverted);
return ret > 0 ? ret : -ret;
}
double MapGenerator::ScaledNoise(double x, double y, double width, double height) {
Vector2 queryPoint = {x, y};
//the "grid points"
Vector2 tl = {snap(x, width), snap(y, height)};
Vector2 tr = {tl.x + width, tl.y};
Vector2 bl = {tl.x, tl.y + height};
Vector2 br = {tl.x + width, tl.y + height};
//influence equasion
double s = Influence(tl, queryPoint, width, height);
double t = Influence(tr, queryPoint, width, height);
double u = Influence(bl, queryPoint, width, height);
double v = Influence(br, queryPoint, width, height);
//Finally, calc the value
double a = s + curve((t - s) / width);
double b = u + curve((v - u) / width);
return curve((b - a) / height);
}
double MapGenerator::ScaledOctave(double x, double y, double width, double height, double octave) {
double ret = 0;
if (octave > 1) {
ret += ScaledOctave(x, y, width/2, height/2, octave-1);
}
return ret / octave + ScaledNoise(x, y, width, height);
}
double MapGenerator::GetPixel(double x, double y, double width, double height, double octave) {
//use this as a decorator function
return curl(ScaledOctave(x, y, width, height, octave));
}
+29
View File
@@ -0,0 +1,29 @@
#configuration of the programs
#server specific settings
server.host = 255.255.255.255
server.port = 21795
server.name = local
server.dbname = database.db
#client specific settings
client.screen.f = false
client.username = Kayne Ruse
client.handle = Ratstail91
client.avatar = elliot2.bmp
#directories
dir.fonts = rsc/graphics/fonts/
dir.logos = rsc/graphics/logos/
dir.sprites = rsc/graphics/sprites/
dir.tilesets = rsc/graphics/tilesets/
dir.interface = rsc/graphics/interface/
dir.scripts = rsc/scripts/
dir.maps = rsc/maps/
#map system
map.savename = servermap
#debugging
Binary file not shown.

After

Width:  |  Height:  |  Size: 65 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 33 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 33 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

Some files were not shown because too many files have changed in this diff Show More