Compare commits

..

202 Commits

Author SHA1 Message Date
Kayne Ruse 9d5a668045 Merge branch 'develop', read more
The trigger system has been fully implemented, as well as a few other
tweaks as the occasional thought came to mind.

Multiple rooms are now fully functional, mostly as a way to test the
triggers. Although there are still no real generation algorithms, a
utility for creating door pairs between given rooms is included in the
scripts directory.

Other changes in this merge include:

* Network updates via lua
* Entity types can be determined in lua
* Database columns are now order independant

It should be noted that only two types of userdata will work as far as
entity names are concerned: Characters and Monsters. I tried getting it to
work for all objects passed to lua, but it proved to be too obtuse.

In theory, I could create a teleport puzzle using what I've written here.
That might be a side project, or a way to test saving & loading systems. I
don't see any reason to delay monsters any longer; hopefully, I can get
them going soon too.
2015-03-13 21:28:05 +11:00
Kayne Ruse 0efb541074 Moved the door pair script to it's own file 2015-03-13 21:24:31 +11:00
Kayne Ruse 4ae58550b5 Changed SetRoomIndex() to SetRoom() 2015-03-13 21:05:24 +11:00
Kayne Ruse d82e3a8b79 Triggers now support exclusion lists 2015-03-13 20:43:47 +11:00
Kayne Ruse 954213f1ff Minor tweak to hCharacterMovement() 2015-03-13 19:36:03 +11:00
Kayne Ruse d2bb3575fc Removed initial world query
The world is queried once the client has the player's character.
2015-03-13 19:12:34 +11:00
Kayne Ruse ca6afb72ad Minor comment tweaks 2015-03-11 20:23:52 +11:00
Kayne Ruse 670ab22e96 Using an entity stack for trigger comparisons 2015-03-11 18:22:09 +11:00
Kayne Ruse 4d71d4cc40 Room transitions are working smoothly, read more
Although the room transitions are working fairly well, it is still heavy
handed, and a number of optimizations can be done. On the whole, this
needs a review.
2015-03-09 23:26:37 +11:00
Kayne Ruse 81b3769188 Implemented networked room chainging function 2015-03-09 21:28:28 +11:00
Kayne Ruse c3c6d42a80 Characters moving via scripts are pushed & popped from the rooms
The delete & create messages still need to be implemented.
2015-03-09 10:27:50 +11:00
Kayne Ruse 3d8ee25ae7 AccountManager's SQL is order-independant 2015-03-09 09:34:38 +11:00
Kayne Ruse decc77e21c Implemented entity.GetType() in lua
This will only work for userdata decented from the Entity base class.
Using something else results in undefined behavior.
2015-03-09 09:04:12 +11:00
Kayne Ruse 501b1e9814 Reduced script verbosity to a degree 2015-03-08 20:08:12 +11:00
Kayne Ruse 01502372c9 Correcting a bug with unimplemented MonsterManager 2015-03-07 15:09:33 +11:00
Kayne Ruse a8c309ec9d Minor comment tweaks 2015-03-06 00:13:12 +11:00
Kayne Ruse 41d6314beb Triggers have a basic response to character collision
I've hacked the trigger system to create a really basic teleport pad,
using the dirt tile as an indicator. This behaviour is not coded into the
engine, but is in fact scripted in lua.

This commit is messy, due to lack of sleep.
2015-03-04 06:16:12 +11:00
Kayne Ruse 74ed93ddc7 Character bounds are stored in the server database
This allows for customization of bounding boxes, as well as highlighting
aspects needed when adding new fields to the characters.
2015-03-04 04:06:16 +11:00
Kayne Ruse 18a7143926 Full trigger creation 2015-03-04 02:21:56 +11:00
Kayne Ruse bd68af5875 Added character iteration to the rooms 2015-03-02 04:26:34 +11:00
Kayne Ruse b8806cc209 Implemented CharacterManager::ForEach() 2015-03-02 02:41:37 +11:00
Kayne Ruse edcb6f05ce Implemented trigger creation & deletion via lua
Triggers now have handles for simple understanding, but there's nothing
preventing multiple triggers from sharing the same name.
2015-03-02 01:00:58 +11:00
Kayne Ruse cb63c9b07c Minor comment tweaks 2015-02-27 05:43:20 +11:00
Kayne Ruse a00ddb3142 Updated trigger names in the server 2015-02-27 05:33:47 +11:00
Kayne Ruse 3431d323e5 Renamed the waypoint system to trogger system 2015-02-27 05:21:40 +11:00
Kayne Ruse 84c4dd0497 Placeholder monster spawn function in map maker 2015-02-27 04:28:28 +11:00
Kayne Ruse 3e6a05307e Minor TODO tweaks 2015-02-27 03:36:47 +11:00
Kayne Ruse c45bda645b Switched TODO: empty to TODO: *function name* 2015-02-27 03:27:37 +11:00
Kayne Ruse 1210d2d24f Minor comment tweaks 2015-02-27 03:06:29 +11:00
Kayne Ruse 894b53e760 Merge branch 'develop' 2015-02-27 02:45:19 +11:00
Kayne Ruse 4630b7e403 PumpCharacterUpdate() works from lua to client, read more
There was a bug in the entity API, where getMotion() was pushing the
origin instead of the motion. This has been corrected. Since this is an
important bug, and because the features for this leg is finished, I'll
merge this to master.
2015-02-27 02:39:27 +11:00
Kayne Ruse 067bf40be7 Moved some utility methods out of the "god class"
These methods are are now functions in server_utilities.hpp
2015-02-27 01:20:05 +11:00
Kayne Ruse d8045ae339 Minor comment tweaks 2015-02-25 21:16:03 +11:00
Kayne Ruse eff23352aa Merge branch 'develop'
Changes:

* "ticking" rooms
* character API
* bare-bones character manager API
* bounds checking in serial_utility.cpp

I have an idea for swapping the existing utility/singleton classes for
namesapces, as I think this would reduce the verbosity that I have to deal
with.
2015-02-23 01:54:46 +11:00
Kayne Ruse 46df0f17b7 Changed a massive swap statement for bounds checks
Instead of using a massive block of case statements in serial_utility.cpp,
I've added FORMAT_* tags to SerialPacketType as a way to destinguish
between type values, at least internally. I can't believe I missed this
for so long.

I've also added a placeholder for the network API, as I was working on
that when I ran into this problem.
2015-02-21 23:46:50 +11:00
Kayne Ruse ddedc06e47 Implemented bare-bones character system API
I need to devise a way to update the clients about changes to their
characters directly from the lua scripts. This isn't too important per se,
but the pattern will be important for the monster and trigger systems.
2015-02-21 21:46:22 +11:00
Kayne Ruse 6a999a8a72 Room API hooks are updated automatically 2015-02-19 03:40:20 +11:00
Kayne Ruse 8a97cb8c2c Checked the tick in Hertz 2015-02-18 00:21:38 +11:00
Kayne Ruse e011e6bdc5 The rooms are ticking 2015-02-18 00:07:38 +11:00
Kayne Ruse a106134dd1 Added hooks to the room system 2015-02-17 23:37:11 +11:00
Kayne Ruse a538cf73d5 Merge branch 'ticks' into develop 2015-02-17 22:23:36 +11:00
Kayne Ruse b273b4c04a Added character API 2015-02-17 22:10:07 +11:00
Kayne Ruse 248d142c2b Reconsidering the server's structure 2015-02-17 21:03:30 +11:00
Kayne Ruse 2cc7260552 Server can handle multiple dropped clients at once 2015-02-17 20:48:03 +11:00
Kayne Ruse fa4ccb6596 Merge branch 'develop' 2015-02-14 23:54:35 +11:00
Kayne Ruse 87af4f1a1e Comment tweaks, updated network version 2015-02-14 23:54:18 +11:00
Kayne Ruse 18b144fa46 Updated client, read more
It seems like the project as a whole is fairly stable now. I'm prepping to
merge this into master, despite the lack of monsters ATM. Hopefully this
break hasn't affected the stability too much.
2015-02-14 23:39:56 +11:00
Kayne Ruse e71d0b3a09 Finished these server tweaks 2015-02-13 23:34:34 +11:00
Kayne Ruse 9710acad6f Lost focus 2015-02-13 02:57:36 +11:00
Kayne Ruse ca2d4c9217 Expanded network protocol, read more
Not really doing much, just busywork with the server's handlers.

I've tweaked the TODO tags as well.
2015-02-13 02:05:10 +11:00
Kayne Ruse bad6cc2fab Moved ip_operators.*pp to common/utilities 2015-02-05 23:06:22 +11:00
Kayne Ruse 95e3ce9a69 Re-added the network version 2015-02-05 22:24:04 +11:00
Kayne Ruse 5583ba4323 Updated TODO comments 2015-02-04 16:52:22 +11:00
Kayne Ruse a18577665a Updated TODO tags 2015-01-23 03:34:53 +11:00
Kayne Ruse 0bdafe7e15 minor file shuffling 2015-01-21 05:21:14 +11:00
Kayne Ruse 38f6ced633 Filled out some client side monster code 2015-01-21 05:09:55 +11:00
Kayne Ruse 65f23bbd1a Fixed issue caused by merges 2015-01-20 22:43:47 +11:00
Kayne Ruse 453a211343 Merge branch 'master' into develop
Conflicts:
	todo.txt
2015-01-20 05:21:00 +11:00
Kayne Ruse 1e8f91a871 rename 2015-01-20 05:18:52 +11:00
Kayne Ruse 2a86a09693 Merge branch 'monsters' into develop
Conflicts:
	client/scenes/in_world.cpp
2015-01-20 05:04:08 +11:00
Kayne Ruse bd878e20ce Added monster message handlers 2015-01-20 05:02:44 +11:00
Kayne Ruse 92a02c7f0c Reverted the server to a LAN system 2015-01-18 21:34:23 +11:00
Kayne Ruse dacb8df674 Split in_world.cpp into three files 2015-01-17 22:09:14 +11:00
Kayne Ruse 7356e8ae77 Removed the dependencies on utility.*pp 2015-01-17 21:46:12 +11:00
Kayne Ruse 9b2e78a68e Split the scenes directory into gameplay_scenes and menu_scenes 2015-01-17 16:57:04 +11:00
Kayne Ruse be90694234 Added network tweaks to client; project builds cleanly 2015-01-15 23:32:04 +11:00
Kayne Ruse e2757a7628 Client now points to home server
I've also tweaked the README.txt
2015-01-14 14:29:55 +11:00
Kayne Ruse 42662c3f61 Replaced HandleCharacterSet*() with HandleCharacterMovement()
This new method rolls three otherwise similar methods together. There is
still a conditional which handles room movements separately, but it's much
smoother, and PumpPacketProximity is utilized much more.

I've also added a stub for graphical attack data via
HandleCharacterAttack()
2015-01-13 02:04:48 +11:00
Kayne Ruse e752dd7b0f Merge branch 'develop' into monsters 2015-01-13 01:37:20 +11:00
Kayne Ruse 44e24b667e Merge branch 'develop' 2015-01-13 01:37:02 +11:00
Kayne Ruse de6eb38516 Reduced CPU load of the client 2015-01-13 01:34:59 +11:00
Kayne Ruse 74bf70c44d Wrote PumpPacketProximity, it works 2015-01-13 01:01:46 +11:00
Kayne Ruse cd06ccc1a5 Room system now uses CharacterData instead of Entity 2015-01-13 00:42:16 +11:00
Kayne Ruse dc40ee64cf common builds cleanly 2015-01-13 00:23:01 +11:00
Kayne Ruse de1cd8d6a8 Began expanding network protocols for monsters
All big feature expansions have begun with SerialPacketType, and this is
no exception.
2015-01-13 00:04:42 +11:00
Kayne Ruse 1923f90329 Added TODO 2015-01-12 01:24:56 +11:00
Kayne Ruse eeac329c49 Merge branch 'develop' 2015-01-12 01:19:39 +11:00
Kayne Ruse f13e8479e4 Refactored scripts, added a smoother for Debug Islan
I've added a simple edge-smoothing function to debug island's generator. It
doesn't handle all edge cases (pun intended), but the proof of concept is
sound. I just wish I could release this...

I've also added exception checks to region.cpp
2015-01-12 01:14:24 +11:00
Kayne Ruse cf1008f0d9 Padded some API internals 2015-01-11 22:31:27 +11:00
Kayne Ruse dfae33cbd1 Merge branch 'rooms' into develop 2015-01-11 20:13:34 +11:00
Kayne Ruse 9f3721247d Replaced a block of code in setup_server.lua with one line 2015-01-11 20:12:50 +11:00
Kayne Ruse d0b2f8e12f Removed MonsterManager's Singleton status, RoomData now has mgr members
RoomData now has monsterMgr and waypointMgr members, so that it can
compare it's characters to the monster & waypoints, etc.

RoomManager has been updated. It now has a database reference, which is
passed to the monsterMgr of new rooms. The room API also has functions
which expose these managers to lua.
2015-01-11 19:47:42 +11:00
Kayne Ruse 051ed0f14c Monster API clones from Entity API, read more
This is my solution for handling inheritance via lua. The Entity class is
only a base class, so the entity API is designed to be copied from, rather
than used directly.

linit.c: It should be noted that the Entity API must always be placed
before the utilizing child APIs. I don't know about how lua handles things
internally, but I'm assuming that this is the case.

There's no real meat in the API code yet, since that's just busy-work.
Right now I feel beter about writing the connective tissue. This case
could aslo extend to the waypoint and monster APIs.

The waypoint system had some API and class methods removed for brevity.
2015-01-11 19:08:31 +11:00
Kayne Ruse 8ea667a0b5 Wrote the WaypointManager API skeleton 2015-01-10 14:03:13 +11:00
Kayne Ruse b391dde089 WaypointManager is no longer a Singleton, wrote waypoint API outline
I'm planning on giving each room it's own waypoint manager, so it can
compare it's waypoints against the characters in that room alone. If it
turns out to be a good pattern, I'll do thae same for monsters.
2015-01-09 13:21:09 +11:00
Kayne Ruse be67906218 Moved TileSheet to common/graphics
Also deleted TileSheet's vestigial API.
2015-01-09 12:41:24 +11:00
Kayne Ruse 70d4233a15 Merge branch 'develop' 2015-01-08 15:44:32 +11:00
Kayne Ruse 31fc5a8fa5 Added Windows 8.1 to the makefile config 2015-01-08 15:44:14 +11:00
Kayne Ruse 1973cfd061 Added a link to WinRAR to README.md 2015-01-08 13:33:09 +11:00
Kayne Ruse 3322783d95 Merge branch 'develop' into rooms 2015-01-03 03:27:34 +11:00
Kayne Ruse 9895e27d5a Merge branch 'develop' 2015-01-03 03:20:54 +11:00
Kayne Ruse 877c0f59d3 Removed preprocessor switch surrounding library headers 2015-01-03 03:20:13 +11:00
Kayne Ruse 92eb75af7e Slight tweaks to waypoints 2015-01-02 23:51:00 +11:00
Kayne Ruse d815f17442 Reimplemented the push/pop entity methods in RoomManager
Some accessors in Entity had to be made const, as they were being called
from lambdas with const parameters.
2015-01-02 23:25:59 +11:00
Kayne Ruse 0344fe0d6d Added a link to the github page to the main menu 2015-01-02 08:49:06 +11:00
Kayne Ruse a10636e067 Merge branch 'bugfix-lambda' 2015-01-02 07:21:52 +11:00
Kayne Ruse 4b8f9b4330 Merge branch 'bugfix-lambda' into develop 2015-01-02 07:21:41 +11:00
Kayne Ruse eb897c81e8 Tentative solution for bug #38 2015-01-02 07:09:04 +11:00
Kayne Ruse 963aca218a Comment tweaks 2015-01-01 01:29:48 +11:00
Kayne Ruse c6981e6216 Merge branch 'develop' 2014-12-31 06:10:24 +11:00
Kayne Ruse 8b8ef088d9 HOTFIX: Incorrect error code checked 2014-12-31 06:10:03 +11:00
Kayne Ruse 6704944105 Updated the map system & APIs 2014-12-31 06:01:03 +11:00
Kayne Ruse 8e50be24d4 Updated room system and room API, more to come
There's a lot of verbosity in the scripts, so it might be beneficial to
redice that at some point.
2014-12-31 04:52:10 +11:00
Kayne Ruse f9c19a630d Added trigger reference to WaypointData, unused
WaypointData also inherits from Entity now, so I could alias Entity's API
for it too. I've also made a number of comment tweaks.
2014-12-31 03:34:06 +11:00
Kayne Ruse 78c04718e0 Removed ManagerInterface, it was a bad idea 2014-12-31 03:05:19 +11:00
Kayne Ruse bb592b2436 Added the waypoint system to the modules
Also fleshed out entity_api.cpp, but that's just filler.
2014-12-30 04:37:56 +11:00
Kayne Ruse 4b5011a579 Merge branch 'develop' 2014-12-30 02:52:26 +11:00
Kayne Ruse f3fb5017b3 Added waypoint API placeholder files 2014-12-30 02:45:35 +11:00
Kayne Ruse 3a9fdd511b Replaced door system with waypoint system 2014-12-30 02:38:25 +11:00
Kayne Ruse 57c6f45c21 Added API placeholder files 2014-12-30 02:19:19 +11:00
Kayne Ruse 8d204dc3c4 Merge branch 'master' into develop
Also saved todo.txt
2014-12-30 01:21:11 +11:00
Kayne Ruse 9413adcf4a Forgot the copyright in the README files 2014-12-30 01:10:43 +11:00
Kayne Ruse 99af76c5b5 Merge branch 'develop'
Conflicts:
	todo.txt
2014-12-27 23:44:54 +11:00
Kayne Ruse cc6458daa7 Merge branch 'high-water-mark' into develop
Thank fuck that's over.
2014-12-27 23:34:51 +11:00
Kayne Ruse 8708cfbee0 I give up, I'm just using the stop-dead system for now. 2014-12-27 23:16:48 +11:00
Kayne Ruse b67e85e87b Moved some messy code from InWorld::Update() to utility methods 2014-12-27 21:00:00 +11:00
Kayne Ruse 33c3143de9 Added unary negative to Vector2
This is the only fragment I'm bothering to salvage from the collisions
branch.
2014-12-27 20:31:09 +11:00
Kayne Ruse ce16fc6969 Merge branch 'develop' into high-water-mark
Conflicts:
	server/server_logic.cpp

Finally merging the changes to develop. This is only the ConfigUtility
skipping missing files, and something with the Timer class, that I'll need
to test the collisions.
2014-12-27 19:28:02 +11:00
Kayne Ruse f6e90d7e39 Fixed controls & hotkeys interferring; smoother logouts 2014-12-27 19:25:49 +11:00
Kayne Ruse ee0b7884a8 Partial collision (box prep) complete; untested 2014-12-27 15:05:34 +11:00
Kayne Ruse 7e5a7f8183 Updated the copyright headers about a week ahead 2014-12-27 13:29:16 +11:00
Kayne Ruse f2d517df9d BUGFIX: Infinitely small motion on an axis after repeated key release;
read more

I've patched this issue by setting motion's elements to
CHARACTER_WALKING_SPEED or negative CHARACTER_WALKING_SPEED if they're
above or below zero, respectively.
2014-12-27 12:33:51 +11:00
Kayne Ruse 6c11aa0927 Characters are moving around in the world 2014-12-27 02:26:44 +11:00
Kayne Ruse 398f1c8bfd Added a room check to the character query 2014-12-27 01:33:10 +11:00
Kayne Ruse 3e2d1a5a56 Implemented client-side HandleCharacterSet*(); untested 2014-12-22 23:09:28 +11:00
Kayne Ruse f52eafdf55 Implemented server-side HandleSetCharacter*(); untested 2014-12-22 22:13:42 +11:00
Kayne Ruse dff04b5b69 Moved server_util.cpp methods; created server_character_methods.cpp 2014-12-21 08:07:55 +11:00
Kayne Ruse 900f623f3b Camera centering and client drop message 2014-12-19 20:33:09 +11:00
Kayne Ruse 44a1edac30 HOTFIX: Patched the stupid auto& for loop with the jenky pattern 2014-12-19 20:11:22 +11:00
Kayne Ruse 2ae2c48819 Added LocalCharacter, removed entityIndex 2014-12-19 19:44:34 +11:00
Kayne Ruse 07af05712b Implemented client-side query 2014-12-19 18:33:41 +11:00
Kayne Ruse 15ea360b8a Replaced lambda implementations with calls to the 'full unload' methods
IT should be noted that ClientManager::CheckConnections() no longer
removes a client; instead, it returns a client index that needs to be
removed via another means. This allows ServerApplication to use the 'full
unload' method.
2014-12-19 17:58:50 +11:00
Kayne Ruse 0d9dfad4a5 Implemented 'full unload' methods, not used yet 2014-12-19 15:52:05 +11:00
Kayne Ruse 7962692641 Implemented client-side character delete; untested 2014-12-19 14:21:05 +11:00
Kayne Ruse 4d1bb17382 Comment tweaks 2014-12-18 09:28:24 +11:00
Kayne Ruse 015631a73d Implemented client-side HandleCharacterCreate 2014-12-18 09:14:11 +11:00
Kayne Ruse 3399053e64 Added an option to skip missing config files 2014-12-16 21:49:50 +11:00
Kayne Ruse ae046977f0 Server state query works, client doesn't use the result yet
Both sides of this message uses QUERY_CHARACTER_EXISTS because I'm just
trying to push forward, without worrying about mistakes I might be making.
I just want to merge this back into the main branch so I can say that I've
actually done something over the last few months.
2014-12-11 08:02:38 +11:00
Kayne Ruse 72f641bf63 Server sends character create & delete messages 2014-12-11 07:12:16 +11:00
Kayne Ruse dbd1289ced Moved map and character management to server_data.cpp 2014-12-09 00:41:09 +11:00
Kayne Ruse de4e539449 Moved the connection code to server_connections.cpp 2014-12-03 00:46:38 +11:00
Kayne Ruse 61f462a882 Server-side HandleCharacterUnload() 2014-12-03 00:06:07 +11:00
Kayne Ruse 5607f76ce7 Server-side HandleCharacterDelete() 2014-12-02 23:41:08 +11:00
Kayne Ruse 0e666d3203 Server accepts and creates the character's data 2014-12-02 23:11:08 +11:00
Kayne Ruse f50406d69f Code tweak 2014-12-01 22:59:26 +11:00
Kayne Ruse cc167180f6 Added support for cleaning up after rejection messages 2014-12-01 22:33:15 +11:00
Kayne Ruse c89f94b681 Missed the map system's nested API table 2014-12-01 00:26:47 +11:00
Kayne Ruse 822ff5827e Map protocol works in theory 2014-12-01 00:13:46 +11:00
Kayne Ruse 8579d7e0d6 Implemented client-side HandleRegionContent() 2014-11-30 23:29:46 +11:00
Kayne Ruse 06eb1f2e9e Minor tweak to the Timer class; kind of pointless 2014-11-30 23:04:54 +11:00
Kayne Ruse b59cd0fe87 Server-side HandleRegionRequest() reimplemented
Note that this locally handles bug #35, and adds a new packet type:

REGION_REJECTION
2014-11-30 22:23:46 +11:00
Kayne Ruse bac8bc2b41 Fixed a misspelled method call 2014-11-26 10:28:57 +11:00
Kayne Ruse e5abd51f76 Two-step login system works perfectly; can't shut the server down
I've also removed a large amount of commented and uncommented code from
in_world.cpp, simply because so much code was dummied out. I can readd
this code as I reimeplement various features.
2014-11-26 10:14:26 +11:00
Kayne Ruse 584b6ea303 Fixed a bug in deserializePacket() 2014-11-26 07:51:24 +11:00
Kayne Ruse 01461deaa5 Set the values for packets, and added getRoom() 2014-11-26 07:11:27 +11:00
Kayne Ruse fa0d232727 Removed one parameter from RoomManager::Create() 2014-11-26 06:41:29 +11:00
Kayne Ruse 6485839dcf Replaced RoomData's hooks with Initialize API function 2014-11-26 06:33:02 +11:00
Kayne Ruse 81a3a92603 Simplified setup_server.lua 2014-11-26 06:12:01 +11:00
Kayne Ruse 9ba76c8987 Added RegionPagerLua destructor 2014-11-26 06:11:27 +11:00
Kayne Ruse 5eeda8235d Fixed the scripts struggling with nested API tables
I actually don't remember what the RoomData's lua references where for,
but I'm pretty srue it wasn't this. I'll figure something out when I've
had a sleep.
2014-11-23 06:40:31 +11:00
Kayne Ruse 20d40d5b81 Implemented two-step logins, basic connections build 2014-11-23 05:47:21 +11:00
Kayne Ruse 5e11077c7a Merge branch 'develop' into server-expansion 2014-11-23 04:13:11 +11:00
Kayne Ruse 5deb6a9d8e Merge branch 'develop' 2014-11-23 04:12:51 +11:00
Kayne Ruse ba81bcba69 Added a README for the demo build 2014-11-22 04:21:15 +11:00
Kayne Ruse 9329274866 Project builds, but with a lot of logic dummied out 2014-11-16 23:16:21 +11:00
Kayne Ruse ace87b438b Began working changes into lobby 2014-11-16 23:02:06 +11:00
Kayne Ruse 1f3c1f32f4 Moved 'renderable' stuff to 'entities' 2014-11-16 22:40:13 +11:00
Kayne Ruse cacd3dcd6d Removed the statistics structure from common/* and server/* 2014-11-16 22:34:12 +11:00
Kayne Ruse 97b7945191 need to go TMP COMMIT 2014-11-14 10:20:04 +11:00
Kayne Ruse a01d75549f Updated todo.txt
I'm so bored I'm working on my game remotely. This is a public access computer without a compiler :/
2014-11-14 10:16:27 +11:00
Kayne Ruse ecd0b43abe Corrected comments
Because this file was originally copied from the map API, there were references to the map. I've corrected this.
2014-11-14 10:05:00 +11:00
Kayne Ruse d35ab24e15 Added TODO 2014-11-14 10:02:15 +11:00
Kayne Ruse 100c4f6522 Added TODO 2014-11-14 10:01:24 +11:00
Kayne Ruse a1c20959fe The server builds using the new packet types; incomplete
Most of this was achieved by dummying out calls in HandlePacket(), so the
server's actual logic is incomplete.
2014-11-09 23:15:09 +11:00
Kayne Ruse 3b9df46510 Merge branch 'network-expansion' into server-expansion 2014-11-08 17:09:04 +11:00
Kayne Ruse f7ba34dcec Fleshed out ClientManager
* Fleshed out the ClientManager internals
* Folded some ServerApplication methods into ClientManager
* Removed Manager references from ServerApplication
* Corrected server_methods.cpp (compiles)
2014-11-08 16:33:27 +11:00
Kayne Ruse 3192524922 Merge commit '0f13956'
* also eliminated ./todo.txt
2014-11-07 00:17:31 +11:00
Kayne Ruse 74234684af Started planning ServerApp refactoring 2014-11-07 00:07:19 +11:00
Kayne Ruse 06e027710f Created the room system's API, and tweaked some other APIs 2014-11-06 22:42:03 +11:00
Kayne Ruse 73d9095604 Minor comment tweaks 2014-11-06 02:00:13 +11:00
Kayne Ruse f2d79225a3 Created '*_data.cpp' files, modified API files a bit 2014-11-06 01:54:27 +11:00
Kayne Ruse daa38413f3 temp script changes 2014-11-06 01:22:08 +11:00
Kayne Ruse a4ed23f6c7 Created a way to coalesce map modules into one table 2014-11-06 01:16:02 +11:00
Kayne Ruse cfdc61c357 Tweaked TODO comments 2014-11-06 00:04:42 +11:00
Kayne Ruse 77b47b4634 Merge branch 'mingw-fix' into server-expansion 2014-11-05 23:55:38 +11:00
Kayne Ruse 0f139562c3 Theoretically resolved jenky cross-compiler compatability 2014-11-05 23:54:10 +11:00
Kayne Ruse fc2bc06992 Made a few tweaks to various managers 2014-11-05 23:43:36 +11:00
Kayne Ruse 8eefdd71b5 Moved the API files back again 2014-11-05 23:07:34 +11:00
Kayne Ruse 966443be3d CharacterData inherits from Entity 2014-11-05 23:02:14 +11:00
Kayne Ruse 5327d91917 Moved API files to their own directory 2014-11-02 20:42:26 +11:00
Kayne Ruse 6399efc227 Created the monster system 2014-10-30 01:05:41 +11:00
Kayne Ruse 7da5de619b Created entity.hpp and door system 2014-10-30 01:01:11 +11:00
Kayne Ruse 0735037f10 Created ClientManager 2014-10-30 00:40:32 +11:00
Kayne Ruse 8c78a5d26c Updated TODO.txt 2014-10-29 23:34:36 +11:00
Kayne Ruse f584dd140b Began work on expanding the network protocols 2014-10-23 23:50:49 +11:00
Kayne Ruse 4434900afc Merge branch 'unix-compat' into develop
Conflicts:
	todo.txt
2014-10-19 05:53:09 +11:00
Kayne Ruse 2a7a2889c6 Merge branch 'unix-compat' 2014-10-19 05:50:13 +11:00
Kayne Ruse e488b15acc Corrected the libs order in the root makefiles
The calls to ConfigUtility::Load() also received some tweaks, to use '/'
instead of '\' for unix compatability. Also removed -llua from graphics
makefile.
2014-10-19 05:40:48 +11:00
Kayne Ruse 387e86de63 Merge remote-tracking branch 'froozen/master' into unix-compat 2014-10-19 05:17:45 +11:00
Kayne Ruse 0e3a042fbb Minor notes in todo.txt 2014-10-19 05:16:42 +11:00
fro_ozen de7167e830 Added unix compatability 2014-10-18 20:10:17 +02:00
Kayne Ruse 40c76b4285 Implemented a few minor changes from the monster branch 2014-10-19 01:25:03 +11:00
176 changed files with 6075 additions and 1774 deletions
+5 -1
View File
@@ -20,13 +20,17 @@ The most recent stable build for Windows can be found [here](https://dl.dropboxu
* [lua 5.2](http://www.lua.org/) - The lua programming language * [lua 5.2](http://www.lua.org/) - The lua programming language
* [SQLite3](http://www.sqlite.org/) - A lightweight SQL database engine * [SQLite3](http://www.sqlite.org/) - A lightweight SQL database engine
## Tools
* [WinRAR](http://www.rarlab.com/) - The best compression tool available IMO; only needed for distribution
## Copyright ## 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).) (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). The current version of Tortuga is released under the [zlib license](http://en.wikipedia.org/wiki/Zlib_License).
Copyright (c) 2013, 2014 Kayne Ruse Copyright (c) 2013-2015 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. 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.
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2013, 2014 /* Copyright: (c) Kayne Ruse 2013-2015
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
@@ -127,7 +127,7 @@ void BaseScene::HandleEvents() {
break; break;
#ifdef USE_EVENT_JOYSTICK #ifdef USE_EVENT_JOYSTICK
//TODO: joystick/gamepad support //EMPTY
#endif #endif
#ifdef USE_EVENT_UNKNOWN #ifdef USE_EVENT_UNKNOWN
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2013, 2014 /* Copyright: (c) Kayne Ruse 2013-2015
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
@@ -59,7 +59,7 @@ protected:
virtual void KeyUp(SDL_KeyboardEvent const&) {} virtual void KeyUp(SDL_KeyboardEvent const&) {}
#ifdef USE_EVENT_JOYSTICK #ifdef USE_EVENT_JOYSTICK
//TODO: joystick/gamepad support //EMPTY
#endif #endif
#ifdef USE_EVENT_UNKNOWN #ifdef USE_EVENT_UNKNOWN
+1 -1
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2013, 2014 /* Copyright: (c) Kayne Ruse 2013-2015
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
+19 -13
View File
@@ -1,11 +1,11 @@
/* Copyright: (c) Kayne Ruse 2013, 2014 /* Copyright: (c) Kayne Ruse 2013-2015
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
* arising from the use of this software. * arising from the use of this software.
* *
* Permission is granted to anyone to use this software for any purpose, * Permission is granted to anyone to use this software for any purpose,
* including commercial ClientApplications, and to alter it and redistribute it * including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions: * freely, subject to the following restrictions:
* *
* 1. The origin of this software must not be misrepresented; you must not * 1. The origin of this software must not be misrepresented; you must not
@@ -37,7 +37,7 @@
#include "main_menu.hpp" #include "main_menu.hpp"
#include "options_menu.hpp" #include "options_menu.hpp"
#include "lobby_menu.hpp" #include "lobby_menu.hpp"
#include "in_world.hpp" #include "world.hpp"
#include "disconnected_screen.hpp" #include "disconnected_screen.hpp"
//------------------------- //-------------------------
@@ -49,7 +49,7 @@ void ClientApplication::Init(int argc, char* argv[]) {
//load the prerequisites //load the prerequisites
ConfigUtility& config = ConfigUtility::GetSingleton(); ConfigUtility& config = ConfigUtility::GetSingleton();
config.Load("rsc\\config.cfg", argc, argv); config.Load("rsc/config.cfg", false, argc, argv);
//------------------------- //-------------------------
//Initialize the APIs //Initialize the APIs
@@ -83,7 +83,6 @@ void ClientApplication::Init(int argc, char* argv[]) {
//debug output //debug output
//------------------------- //-------------------------
//TODO: enable/disable these with a switch
#define DEBUG_OUTPUT_VAR(x) std::cout << "\t" << #x << ": " << x << std::endl; #define DEBUG_OUTPUT_VAR(x) std::cout << "\t" << #x << ": " << x << std::endl;
std::cout << "Internal sizes:" << std::endl; std::cout << "Internal sizes:" << std::endl;
@@ -137,11 +136,17 @@ void ClientApplication::Proc() {
realTime = Clock::now(); realTime = Clock::now();
//simulate game time //simulate game time
while (simTime < realTime) { if (simTime < realTime) {
//call each user defined function while (simTime < realTime) {
activeScene->RunFrame(); //call each user defined function
//~60 FPS activeScene->RunFrame();
simTime += std::chrono::duration<int, std::milli>(16); //~60 FPS
simTime += std::chrono::duration<int, std::milli>(16);
}
}
else {
//give the machine a break
SDL_Delay(10);
} }
//draw the game to the screen //draw the game to the screen
@@ -164,6 +169,7 @@ void ClientApplication::Quit() {
//------------------------- //-------------------------
void ClientApplication::LoadScene(SceneList sceneIndex) { void ClientApplication::LoadScene(SceneList sceneIndex) {
//BUG: #16 Resources are being reloaded between scenes
UnloadScene(); UnloadScene();
switch(sceneIndex) { switch(sceneIndex) {
//add scene creation calls here //add scene creation calls here
@@ -178,10 +184,10 @@ void ClientApplication::LoadScene(SceneList sceneIndex) {
activeScene = new OptionsMenu(); activeScene = new OptionsMenu();
break; break;
case SceneList::LOBBYMENU: case SceneList::LOBBYMENU:
activeScene = new LobbyMenu(&clientIndex, &accountIndex); //TODO: can I use the ConfigUtility for these parameters? activeScene = new LobbyMenu(&clientIndex, &accountIndex);
break; break;
case SceneList::INWORLD: case SceneList::WORLD:
activeScene = new InWorld(&clientIndex, &accountIndex); activeScene = new World(&clientIndex, &accountIndex);
break; break;
case SceneList::DISCONNECTEDSCREEN: case SceneList::DISCONNECTEDSCREEN:
activeScene = new DisconnectedScreen(); activeScene = new DisconnectedScreen();
+1 -1
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2013, 2014 /* Copyright: (c) Kayne Ruse 2013-2015
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2014 /* Copyright: (c) Kayne Ruse 2013-2015
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
@@ -19,5 +19,5 @@
* 3. This notice may not be removed or altered from any source * 3. This notice may not be removed or altered from any source
* distribution. * distribution.
*/ */
#include "base_monster.hpp" #include "terminal_error.hpp"
@@ -0,0 +1,34 @@
/* Copyright: (c) Kayne Ruse 2013-2015
*
* 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 TERMINALERROR_HPP_
#define TERMINALERROR_HPP_
#include <stdexcept>
#include <string>
class terminal_error: public std::runtime_error {
public:
explicit terminal_error(const std::string& str): runtime_error(str) {}
explicit terminal_error(const char* cstr): runtime_error(cstr) {}
};
#endif
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2014 /* Copyright: (c) Kayne Ruse 2013-2015
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
@@ -21,6 +21,12 @@
*/ */
#include "base_character.hpp" #include "base_character.hpp"
#include "config_utility.hpp"
//-------------------------
//graphics
//-------------------------
void BaseCharacter::CorrectSprite() { void BaseCharacter::CorrectSprite() {
//NOTE: These must correspond to the sprite sheet in use //NOTE: These must correspond to the sprite sheet in use
if (motion.y > 0) { if (motion.y > 0) {
@@ -45,3 +51,33 @@ void BaseCharacter::CorrectSprite() {
sprite.SetXIndex(0); sprite.SetXIndex(0);
} }
} }
//-------------------------
//metadata
//-------------------------
int BaseCharacter::SetOwner(int i) {
return owner = i;
}
int BaseCharacter::GetOwner() {
return owner;
}
std::string BaseCharacter::SetHandle(std::string s) {
return handle = s;
}
std::string BaseCharacter::GetHandle() const {
return handle;
}
std::string BaseCharacter::SetAvatar(std::string s) {
avatar = s;
sprite.LoadSurface(ConfigUtility::GetSingleton()["dir.sprites"] + avatar, CHARACTER_CELLS_X, CHARACTER_CELLS_Y);
return avatar;
}
std::string BaseCharacter::GetAvatar() const {
return avatar;
}
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2014 /* Copyright: (c) Kayne Ruse 2013-2015
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
@@ -24,12 +24,12 @@
//components //components
#include "character_defines.hpp" #include "character_defines.hpp"
#include "renderable.hpp" #include "entity.hpp"
//std namespace //std namespace
#include <string> #include <string>
class BaseCharacter : public Renderable { class BaseCharacter: public Entity {
public: public:
BaseCharacter() = default; BaseCharacter() = default;
virtual ~BaseCharacter() = default; virtual ~BaseCharacter() = default;
@@ -38,14 +38,14 @@ public:
void CorrectSprite(); void CorrectSprite();
//metadata //metadata
int SetOwner(int i) { return owner = i; } int SetOwner(int i);
int GetOwner() { return owner; } int GetOwner();
std::string SetHandle(std::string s) { return handle = s; } std::string SetHandle(std::string s);
std::string GetHandle() const { return handle; } std::string GetHandle() const;
std::string SetAvatar(std::string s) { return avatar = s; } std::string SetAvatar(std::string s);
std::string GetAvatar() const { return avatar; } std::string GetAvatar() const;
private: protected:
//metadata //metadata
int owner; int owner;
std::string handle; std::string handle;
+46
View File
@@ -0,0 +1,46 @@
/* Copyright: (c) Kayne Ruse 2013-2015
*
* 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 "base_monster.hpp"
#include "config_utility.hpp"
void BaseMonster::CorrectSprite() {
//TODO: (9) BaseMonster::CorrectSprite()
}
std::string BaseMonster::SetHandle(std::string s) {
return handle = s;
}
std::string BaseMonster::GetHandle() const {
return handle;
}
std::string BaseMonster::SetAvatar(std::string s) {
avatar = s;
sprite.LoadSurface(ConfigUtility::GetSingleton()["dir.sprites"] + avatar, 4, 1);
return avatar;
}
std::string BaseMonster::GetAvatar() const {
return avatar;
}
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2014 /* Copyright: (c) Kayne Ruse 2013-2015
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
@@ -19,24 +19,27 @@
* 3. This notice may not be removed or altered from any source * 3. This notice may not be removed or altered from any source
* distribution. * distribution.
*/ */
#ifndef STATISTICS_HPP_ #ifndef BASEMONSTER_HPP_
#define STATISTICS_HPP_ #define BASEMONSTER_HPP_
struct Statistics { #include "entity.hpp"
int level = 0;
int exp = 0; class BaseMonster: public Entity {
int maxHP = 0; public:
int health = 0; BaseMonster() = default;
int maxMP = 0; virtual ~BaseMonster() = default;
int mana = 0;
int attack = 0; void CorrectSprite();
int defence = 0;
int intelligence = 0; std::string SetHandle(std::string s);
int resistance = 0; std::string GetHandle() const;
int speed = 0; std::string SetAvatar(std::string s);
float accuracy = 0.0; std::string GetAvatar() const;
float evasion = 0.0;
float luck = 0.0; protected:
//metadata
std::string handle;
std::string avatar;
}; };
#endif #endif
+63
View File
@@ -0,0 +1,63 @@
/* Copyright: (c) Kayne Ruse 2013-2015
*
* 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 "entity.hpp"
void Entity::Update() {
origin += motion;
sprite.Update(0.016);
}
void Entity::DrawTo(SDL_Surface* const dest, int camX, int camY) {
sprite.DrawTo(dest, origin.x - camX, origin.y - camY);
}
SpriteSheet* Entity::GetSprite() {
return &sprite;
}
//-------------------------
//accessors & mutators
//-------------------------
Vector2 Entity::SetOrigin(Vector2 v) {
return origin = v;
}
Vector2 Entity::SetMotion(Vector2 v) {
return motion = v;
}
BoundingBox Entity::SetBounds(BoundingBox b) {
return bounds = b;
}
Vector2 Entity::GetOrigin() {
return origin;
}
Vector2 Entity::GetMotion() {
return motion;
}
BoundingBox Entity::GetBounds() {
return bounds;
}
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2014 /* Copyright: (c) Kayne Ruse 2013-2015
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
@@ -19,37 +19,37 @@
* 3. This notice may not be removed or altered from any source * 3. This notice may not be removed or altered from any source
* distribution. * distribution.
*/ */
#ifndef RENDERABLE_HPP_ #ifndef ENTITY_HPP_
#define RENDERABLE_HPP_ #define ENTITY_HPP_
#include "bounding_box.hpp" #include "bounding_box.hpp"
#include "sprite_sheet.hpp" #include "sprite_sheet.hpp"
#include "vector2.hpp" #include "vector2.hpp"
class Renderable { //The base class for all objects in the world
class Entity {
public: public:
Renderable() = default;
virtual ~Renderable() = default;
virtual void Update(); virtual void Update();
virtual void DrawTo(SDL_Surface* const, int camX, int camY); virtual void DrawTo(SDL_Surface* const, int camX, int camY);
SpriteSheet* GetSprite() { return &sprite; } SpriteSheet* GetSprite();
//position //accessors & mutators
Vector2 SetOrigin(Vector2 v) { return origin = v; } Vector2 SetOrigin(Vector2 v);
Vector2 GetOrigin() const { return origin; } Vector2 SetMotion(Vector2 v);
Vector2 SetMotion(Vector2 v) { return motion = v; } BoundingBox SetBounds(BoundingBox b);
Vector2 GetMotion() const { return motion; }
//collision Vector2 GetOrigin();
BoundingBox SetBounds(BoundingBox b) { return bounds = b; } Vector2 GetMotion();
BoundingBox GetBounds() { return bounds; } BoundingBox GetBounds();
protected:
Entity() = default;
virtual ~Entity() = default;
protected: //TODO: should be private
SpriteSheet sprite; SpriteSheet sprite;
Vector2 origin = {0, 0}; Vector2 origin;
Vector2 motion = {0, 0}; Vector2 motion;
BoundingBox bounds; BoundingBox bounds;
}; };
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2014 /* Copyright: (c) Kayne Ruse 2013-2015
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
@@ -21,3 +21,15 @@
*/ */
#include "local_character.hpp" #include "local_character.hpp"
#include <iostream>
bool LocalCharacter::ProcessCollisionGrid(std::list<BoundingBox> boxList) {
for(auto& box : boxList) {
if (box.CheckOverlap(origin + bounds)) {
origin -= motion;
motion = {0, 0};
return true;
}
}
return false;
}
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2014 /* Copyright: (c) Kayne Ruse 2013-2015
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
@@ -23,18 +23,20 @@
#define LOCALCHARACTER_HPP_ #define LOCALCHARACTER_HPP_
#include "base_character.hpp" #include "base_character.hpp"
#include "statistics.hpp" #include "bounding_box.hpp"
#include "vector2.hpp"
class LocalCharacter : public BaseCharacter { #include <list>
class LocalCharacter: public BaseCharacter {
public: public:
LocalCharacter() = default; LocalCharacter() = default;
~LocalCharacter() = default; virtual ~LocalCharacter() = default;
Statistics* GetBaseStats() { return &baseStats; } bool ProcessCollisionGrid(std::list<BoundingBox>);
private: private:
Statistics baseStats; //NOTE: NO MEMBERS
//TODO: weapons, armour, buffs, debuffs, etc.
}; };
#endif #endif
+37
View File
@@ -0,0 +1,37 @@
#config
INCLUDES+=. .. ../client_utilities ../entities ../../common/gameplay ../../common/graphics ../../common/map ../../common/network ../../common/network/packet_types ../../common/ui ../../common/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)/,client.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
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2013, 2014 /* Copyright: (c) Kayne Ruse 2013-2015
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
@@ -25,9 +25,10 @@
//maps //maps
#include "region_pager_base.hpp" #include "region_pager_base.hpp"
//networking //utilities
#include "udp_network_utility.hpp" #include "udp_network_utility.hpp"
#include "serial_packet.hpp" #include "serial_packet.hpp"
#include "config_utility.hpp"
//graphics //graphics
#include "image.hpp" #include "image.hpp"
@@ -38,22 +39,21 @@
//common //common
#include "frame_rate.hpp" #include "frame_rate.hpp"
#include "base_character.hpp"
#include "local_character.hpp"
//client //client
#include "base_scene.hpp" #include "base_scene.hpp"
#include "base_monster.hpp"
#include "local_character.hpp"
//STL //STL
#include <map> #include <map>
#include <chrono> #include <chrono>
class InWorld : public BaseScene { class World: public BaseScene {
public: public:
//Public access members //Public access members
InWorld(int* const argClientIndex, int* const argAccountIndex); World(int* const argClientIndex, int* const argAccountIndex);
~InWorld(); ~World();
protected: protected:
//Frame loop //Frame loop
@@ -71,33 +71,65 @@ protected:
void KeyDown(SDL_KeyboardEvent const&); void KeyDown(SDL_KeyboardEvent const&);
void KeyUp(SDL_KeyboardEvent const&); void KeyUp(SDL_KeyboardEvent const&);
//Network handlers //handle incoming traffic
void HandlePacket(SerialPacket* const); void HandlePacket(SerialPacket* const);
void HandlePing(ServerPacket* const);
void HandlePong(ServerPacket* const);
void HandleDisconnect(ClientPacket* const);
void HandleCharacterNew(CharacterPacket* const);
void HandleCharacterDelete(CharacterPacket* const);
void HandleCharacterUpdate(CharacterPacket* const);
void HandleCharacterRejection(TextPacket* const);
void HandleRegionContent(RegionPacket* const);
//Server control //heartbeat system
void RequestSynchronize(); void hPing(ServerPacket* const);
void SendPlayerUpdate(); void hPong(ServerPacket* const);
void RequestDisconnect();
void RequestShutDown();
void RequestRegion(int roomIndex, int x, int y);
//utilities void CheckHeartBeat();
//basic connections
void SendLogoutRequest();
void SendDisconnectRequest();
void SendAdminDisconnectForced();
void SendAdminShutdownRequest();
void hLogoutResponse(ClientPacket* const);
void hDisconnectResponse(ClientPacket* const);
void hAdminDisconnectForced(ClientPacket* const);
//map management
void SendRegionRequest(int roomIndex, int x, int y);
void hRegionContent(RegionPacket* const);
void UpdateMap(); void UpdateMap();
//shared parameters //character management
UDPNetworkUtility& network = UDPNetworkUtility::GetSingleton(); void hCharacterUpdate(CharacterPacket* const);
void hCharacterCreate(CharacterPacket* const);
void hCharacterDelete(CharacterPacket* const);
void hQueryCharacterExists(CharacterPacket* const);
void hQueryCharacterStats(CharacterPacket* const);
void hQueryCharacterLocation(CharacterPacket* const);
void hCharacterMovement(CharacterPacket* const);
void hCharacterAttack(CharacterPacket* const);
void hCharacterDamage(CharacterPacket* const);
//monster management
void hMonsterCreate(MonsterPacket* const);
void hMonsterDelete(MonsterPacket* const);
void hQueryMonsterExists(MonsterPacket* const);
void hQueryMonsterStats(MonsterPacket* const);
void hQueryMonsterLocation(MonsterPacket* const);
void hMonsterMovement(MonsterPacket* const);
void hMonsterAttack(MonsterPacket* const);
void hMonsterDamage(MonsterPacket* const);
//chat
void hTextBroadcast(TextPacket* const);
void hTextSpeech(TextPacket* const);
void hTextWhisper(TextPacket* const);
//general gameplay
void SendLocalCharacterMovement();
std::list<BoundingBox> GenerateCollisionGrid(Entity*, int tileWidth, int tileHeight);
//indexes
int& clientIndex; int& clientIndex;
int& accountIndex; int& accountIndex;
int characterIndex = -1; int characterIndex = -1;
std::map<int, BaseCharacter> characterMap; int roomIndex = -1;
//graphics //graphics
Image buttonImage; Image buttonImage;
@@ -110,6 +142,7 @@ protected:
//UI //UI
Button disconnectButton; Button disconnectButton;
Button shutDownButton; Button shutDownButton;
FrameRate fps;
//the camera structure //the camera structure
struct { struct {
@@ -117,16 +150,21 @@ protected:
int width = 0, height = 0; int width = 0, height = 0;
int marginX = 0, marginY = 0; int marginX = 0, marginY = 0;
} camera; } camera;
FrameRate fps;
//game //entities
BaseCharacter* localCharacter = nullptr; std::map<int, BaseCharacter> characterMap;
std::map<int, BaseMonster> monsterMap;
LocalCharacter* localCharacter = nullptr;
//connections //heartbeat
//TODO: This needs it's own utility, for both InWorld and InCombat //TODO: (2) Heartbeat needs it's own utility
typedef std::chrono::steady_clock Clock; typedef std::chrono::steady_clock Clock;
Clock::time_point lastBeat = Clock::now(); Clock::time_point lastBeat = Clock::now();
int attemptedBeats = 0; int attemptedBeats = 0;
//ugly references; I hate this
ConfigUtility& config = ConfigUtility::GetSingleton();
UDPNetworkUtility& network = UDPNetworkUtility::GetSingleton();
}; };
#endif #endif
+239
View File
@@ -0,0 +1,239 @@
/* Copyright: (c) Kayne Ruse 2013-2015
*
* 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 "world.hpp"
#include "channels.hpp"
#include <iostream>
#include <sstream>
#include <stdexcept>
//-------------------------
//character management
//-------------------------
//DOCS: preexisting characters will result in query responses
//DOCS: new characters will result in create messages
//DOCS: this client's character will exist in both (skipped)
void World::hCharacterUpdate(CharacterPacket* const argPacket) {
//TODO: (1) Authentication
//NOTE: applies to the local character too
//check that this character exists
std::map<int, BaseCharacter>::iterator characterIt = characterMap.find(argPacket->characterIndex);
if (characterIt != characterMap.end()) {
//update the origin and motion, if there's a difference
if (characterIt->second.GetOrigin() != argPacket->origin) {
characterIt->second.SetOrigin(argPacket->origin);
}
if (characterIt->second.GetMotion() != argPacket->motion) {
characterIt->second.SetMotion(argPacket->motion);
characterIt->second.CorrectSprite(); //only correct the sprite if the motion changes
}
}
}
void World::hCharacterCreate(CharacterPacket* const argPacket) {
//prevent double message
if (characterMap.find(argPacket->characterIndex) != characterMap.end()) {
std::ostringstream msg;
msg << "Double character creation event; ";
msg << "Index: " << argPacket->characterIndex << "; ";
msg << "Handle: " << argPacket->handle;
throw(std::runtime_error(msg.str()));
}
//implicity create and retrieve the entity
BaseCharacter* character = &characterMap[argPacket->characterIndex];
//fill the character's info
character->SetHandle(argPacket->handle);
character->SetAvatar(argPacket->avatar);
character->SetOwner(argPacket->accountIndex);
character->SetOrigin(argPacket->origin);
character->SetMotion(argPacket->motion);
character->SetBounds(argPacket->bounds);
character->CorrectSprite();
//check for this player's character
if (character->GetOwner() == accountIndex) {
localCharacter = static_cast<LocalCharacter*>(character);
//focus the camera on this character's sprite
camera.marginX = (camera.width / 2 - localCharacter->GetSprite()->GetImage()->GetClipW() / 2);
camera.marginY = (camera.height/ 2 - localCharacter->GetSprite()->GetImage()->GetClipH() / 2);
//focus on this character's info
characterIndex = argPacket->characterIndex;
roomIndex = argPacket->roomIndex;
//query the world state (room)
CharacterPacket newPacket;
memset(&newPacket, 0, MAX_PACKET_SIZE);
newPacket.type = SerialPacketType::QUERY_CHARACTER_EXISTS;
newPacket.roomIndex = roomIndex;
network.SendTo(Channels::SERVER, &newPacket);
newPacket.type = SerialPacketType::QUERY_MONSTER_EXISTS;
network.SendTo(Channels::SERVER, &newPacket);
}
//debug
std::cout << "Character Create, total: " << characterMap.size() << std::endl;
}
void World::hCharacterDelete(CharacterPacket* const argPacket) {
//ignore if this character doesn't exist
std::map<int, BaseCharacter>::iterator characterIt = characterMap.find(argPacket->characterIndex);
if (characterIt == characterMap.end()) {
return;
}
//check for this player's character
if ((*characterIt).second.GetOwner() == accountIndex) {
localCharacter = nullptr;
//clear the camera
camera.marginX = 0;
camera.marginY = 0;
//clear the room
roomIndex = -1;
regionPager.UnloadAll();
characterMap.clear();
monsterMap.clear();
}
else {
//remove this character
characterMap.erase(characterIt);
}
//debug
std::cout << "Character Delete, total: " << characterMap.size() << std::endl;
}
void World::hQueryCharacterExists(CharacterPacket* const argPacket) {
//prevent a double message about this player's character
// if (argPacket->accountIndex == accountIndex) {
// return;
// }
//ignore characters in a different room (sub-optimal)
if (argPacket->roomIndex != roomIndex) {
return;
}
//implicitly construct the character if it doesn't exist
BaseCharacter* character = &characterMap[argPacket->characterIndex];
//set/update the character's info
character->SetOrigin(argPacket->origin);
character->SetMotion(argPacket->motion);
character->SetBounds({CHARACTER_BOUNDS_X, CHARACTER_BOUNDS_Y, CHARACTER_BOUNDS_WIDTH, CHARACTER_BOUNDS_HEIGHT});
character->SetHandle(argPacket->handle);
character->SetAvatar(argPacket->avatar);
character->SetOwner(argPacket->accountIndex);
character->CorrectSprite();
//debug
std::cout << "Character Query, total: " << characterMap.size() << std::endl;
}
void World::hQueryCharacterStats(CharacterPacket* const argPacket) {
//TODO: (9) World::hQueryCharacterStats()
}
void World::hQueryCharacterLocation(CharacterPacket* const argPacket) {
//TODO: (9) World::hQueryCharacterLocation()
}
void World::hCharacterMovement(CharacterPacket* const argPacket) {
//TODO: (1) Authentication
if (argPacket->characterIndex == characterIndex) {
return;
}
//check that this character exists
std::map<int, BaseCharacter>::iterator characterIt = characterMap.find(argPacket->characterIndex);
if (characterIt != characterMap.end()) {
//set the origin and motion
characterIt->second.SetOrigin(argPacket->origin);
characterIt->second.SetMotion(argPacket->motion);
characterIt->second.CorrectSprite();
}
}
void World::hCharacterAttack(CharacterPacket* const argPacket) {
//TODO: (9) World::hCharacterAttack()
}
void World::hCharacterDamage(CharacterPacket* const argPacket) {
//TODO: (9) World::hCharacterDamage()
}
//-------------------------
//player movement & collision
//-------------------------
void World::SendLocalCharacterMovement() {
CharacterPacket newPacket;
newPacket.type = SerialPacketType::CHARACTER_MOVEMENT;
newPacket.accountIndex = accountIndex;
newPacket.characterIndex = characterIndex;
newPacket.roomIndex = roomIndex;
newPacket.origin = localCharacter->GetOrigin();
newPacket.motion = localCharacter->GetMotion();
network.SendTo(Channels::SERVER, &newPacket);
}
std::list<BoundingBox> World::GenerateCollisionGrid(Entity* ptr, int tileWidth, int tileHeight) {
//prepare for collisions
BoundingBox wallBounds = {0, 0, tileWidth, tileHeight};
std::list<BoundingBox> boxList;
//NOTE: for loops were too dense to work with, so I've just used while loops
//outer loop
wallBounds.x = snapToBase((double)wallBounds.w, ptr->GetOrigin().x);
while(wallBounds.x < (ptr->GetOrigin() + ptr->GetBounds()).x + ptr->GetBounds().w) {
//inner loop
wallBounds.y = snapToBase((double)wallBounds.h, ptr->GetOrigin().y);
while(wallBounds.y < (ptr->GetOrigin() + ptr->GetBounds()).y + ptr->GetBounds().h) {
//check to see if this tile is solid
if (regionPager.GetSolid(wallBounds.x / wallBounds.w, wallBounds.y / wallBounds.h)) {
//push onto the box set
boxList.push_front(wallBounds);
}
//increment
wallBounds.y += wallBounds.h;
}
//increment
wallBounds.x += wallBounds.w;
}
return std::move(boxList);
}
+39
View File
@@ -0,0 +1,39 @@
/* Copyright: (c) Kayne Ruse 2013-2015
*
* 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 "world.hpp"
//-------------------------
//chat
//-------------------------
void World::hTextBroadcast(TextPacket* const argPacket) {
//TODO: (9) World::hTextBroadcast()
}
void World::hTextSpeech(TextPacket* const argPacket) {
//TODO: (9) World::hTextSpeech()
}
void World::hTextWhisper(TextPacket* const argPacket) {
//TODO: (9) World::hTextWhisper()
}
@@ -0,0 +1,134 @@
/* Copyright: (c) Kayne Ruse 2013-2015
*
* 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 "world.hpp"
#include "channels.hpp"
#include "ip_operators.hpp"
#include <chrono>
#include <sstream>
#include <stdexcept>
//-------------------------
//heartbeat system
//-------------------------
void World::hPing(ServerPacket* const argPacket) {
ServerPacket newPacket;
newPacket.type = SerialPacketType::PONG;
network.SendTo(argPacket->srcAddress, &newPacket);
}
void World::hPong(ServerPacket* const argPacket) {
if (*network.GetIPAddress(Channels::SERVER) != argPacket->srcAddress) {
throw(std::runtime_error("Heartbeat message received from an unknown source"));
}
attemptedBeats = 0;
lastBeat = Clock::now();
}
void World::CheckHeartBeat() {
//check the connection (heartbeat)
if (Clock::now() - lastBeat > std::chrono::seconds(3)) {
if (attemptedBeats > 2) {
//escape to the disconnect screen
SendDisconnectRequest();
SetNextScene(SceneList::DISCONNECTEDSCREEN);
ConfigUtility::GetSingleton()["client.disconnectMessage"] = "Error: Lost connection to the server";
}
else {
ServerPacket newPacket;
newPacket.type = SerialPacketType::PING;
network.SendTo(Channels::SERVER, &newPacket);
attemptedBeats++;
lastBeat = Clock::now();
}
}
}
//-------------------------
//Connection control
//-------------------------
void World::SendLogoutRequest() {
ClientPacket newPacket;
//send a logout request
newPacket.type = SerialPacketType::LOGOUT_REQUEST;
newPacket.accountIndex = accountIndex;
network.SendTo(Channels::SERVER, &newPacket);
}
void World::SendDisconnectRequest() {
ClientPacket newPacket;
//send a disconnect request
newPacket.type = SerialPacketType::DISCONNECT_REQUEST;
newPacket.clientIndex = clientIndex;
network.SendTo(Channels::SERVER, &newPacket);
}
void World::SendAdminDisconnectForced() {
//TODO: (9) World::SendAdminDisconnectForced()
}
void World::SendAdminShutdownRequest() {
ClientPacket newPacket;
//send a shutdown request
newPacket.type = SerialPacketType::ADMIN_SHUTDOWN_REQUEST;
newPacket.accountIndex = accountIndex;
network.SendTo(Channels::SERVER, &newPacket);
}
void World::hLogoutResponse(ClientPacket* const argPacket) {
if (localCharacter) {
characterMap.erase(characterIndex);
localCharacter = nullptr;
}
accountIndex = -1;
characterIndex = -1;
//reset the camera
camera.marginX = camera.marginY = 0;
//because, why not? I guess...
SendDisconnectRequest();
}
void World::hDisconnectResponse(ClientPacket* const argPacket) {
hLogoutResponse(argPacket);//shortcut
SetNextScene(SceneList::DISCONNECTEDSCREEN);
ConfigUtility::GetSingleton()["client.disconnectMessage"] = "You have successfully logged out";
}
void World::hAdminDisconnectForced(ClientPacket* const argPacket) {
hDisconnectResponse(argPacket);//shortcut
SetNextScene(SceneList::DISCONNECTEDSCREEN);
ConfigUtility::GetSingleton()["client.disconnectMessage"] = "You have been forcibly disconnected by the server";
}
+414
View File
@@ -0,0 +1,414 @@
/* Copyright: (c) Kayne Ruse 2013-2015
*
* 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 "world.hpp"
#include "channels.hpp"
#include "terminal_error.hpp"
#include <stdexcept>
#include <algorithm>
#include <cmath>
#include <iostream>
#include <sstream>
//-------------------------
//Public access members
//-------------------------
World::World(int* const argClientIndex, int* const argAccountIndex):
clientIndex(*argClientIndex),
accountIndex(*argAccountIndex)
{
//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: (2) Tile size and tile sheet should be loaded elsewhere
tileSheet.Load(config["dir.tilesets"] + "overworld.bmp", 32, 32);
//Send the character data
CharacterPacket newPacket;
newPacket.type = SerialPacketType::CHARACTER_LOAD;
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);
//set the camera's values
camera.width = GetScreen()->w;
camera.height = GetScreen()->h;
//debug
//
}
World::~World() {
//unload the local data
characterMap.clear();
monsterMap.clear();
}
//-------------------------
//Frame loop
//-------------------------
void World::FrameStart() {
//
}
void World::Update() {
//create and zero the buffer
SerialPacket* packetBuffer = reinterpret_cast<SerialPacket*>(new char[MAX_PACKET_SIZE]);
memset(packetBuffer, 0, MAX_PACKET_SIZE);
try {
//suck in and process all waiting packets
while(network.Receive(packetBuffer)) {
HandlePacket(packetBuffer);
}
}
catch(terminal_error& e) {
throw(e);
}
catch(std::exception& e) {
std::cerr << "HandlePacket Error: " << e.what() << std::endl;
}
//free the buffer
delete reinterpret_cast<char*>(packetBuffer);
//heartbeat system
CheckHeartBeat();
//update all entities
for (auto& it : characterMap) {
it.second.Update();
}
for (auto& it : monsterMap) {
it.second.Update();
}
//update the map
UpdateMap();
//skip the rest without a local character
if (!localCharacter) {
return;
}
//get the collidable boxes
std::list<BoundingBox> boxList = GenerateCollisionGrid(localCharacter, tileSheet.GetTileW(), tileSheet.GetTileH());
//process the collisions
if (localCharacter->ProcessCollisionGrid(boxList)) {
localCharacter->CorrectSprite();
SendLocalCharacterMovement();
}
//update the camera
camera.x = localCharacter->GetOrigin().x - camera.marginX;
camera.y = localCharacter->GetOrigin().y - camera.marginY;
}
void World::FrameEnd() {
//
}
void World::RenderFrame() {
// SDL_FillRect(GetScreen(), 0, 0);
Render(GetScreen());
SDL_Flip(GetScreen());
fps.Calculate();
}
void World::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 the entities
for (auto& it : characterMap) {
//BUG: #29 Characters (and other entities) are drawn out of order
it.second.DrawTo(screen, camera.x, camera.y);
}
for (auto& it : monsterMap) {
it.second.DrawTo(screen, camera.x, camera.y);
}
//draw UI
disconnectButton.DrawTo(screen);
shutDownButton.DrawTo(screen);
std::ostringstream msg;
msg << fps.GetFrameRate();
font.DrawStringTo(msg.str(), screen, 0, 0);
}
//-------------------------
//Event handlers
//-------------------------
void World::QuitEvent() {
//two-step logout
SendDisconnectRequest();
SetNextScene(SceneList::QUIT);
}
void World::MouseMotion(SDL_MouseMotionEvent const& motion) {
disconnectButton.MouseMotion(motion);
shutDownButton.MouseMotion(motion);
}
void World::MouseButtonDown(SDL_MouseButtonEvent const& button) {
disconnectButton.MouseButtonDown(button);
shutDownButton.MouseButtonDown(button);
}
void World::MouseButtonUp(SDL_MouseButtonEvent const& button) {
if (disconnectButton.MouseButtonUp(button) == Button::State::HOVER && button.button == SDL_BUTTON_LEFT) {
SendLogoutRequest();
}
if (shutDownButton.MouseButtonUp(button) == Button::State::HOVER && button.button == SDL_BUTTON_LEFT) {
SendAdminShutdownRequest();
}
}
void World::KeyDown(SDL_KeyboardEvent const& key) {
//hotkeys
switch(key.keysym.sym) {
case SDLK_ESCAPE:
//TODO: (3) the escape key should actually control menus and stuff
SendLogoutRequest();
return;
}
//character movement
if (!localCharacter) {
return;
}
Vector2 motion = localCharacter->GetMotion();
switch(key.keysym.sym) {
case SDLK_w:
motion.y -= CHARACTER_WALKING_SPEED;
break;
case SDLK_a:
motion.x -= CHARACTER_WALKING_SPEED;
break;
case SDLK_s:
motion.y += CHARACTER_WALKING_SPEED;
break;
case SDLK_d:
motion.x += CHARACTER_WALKING_SPEED;
break;
default:
//DOCS: prevents wrong keys screwing with character movement
return;
}
//handle diagonals
if (motion.x != 0 && motion.y != 0) {
motion *= CHARACTER_WALKING_MOD;
}
//set the info
localCharacter->SetMotion(motion);
localCharacter->CorrectSprite();
SendLocalCharacterMovement();
}
void World::KeyUp(SDL_KeyboardEvent const& key) {
//character movement
if (!localCharacter) {
return;
}
Vector2 motion = localCharacter->GetMotion();
switch(key.keysym.sym) {
case SDLK_w:
motion.y = std::min(0.0, motion.y += CHARACTER_WALKING_SPEED);
break;
case SDLK_a:
motion.x = std::min(0.0, motion.x += CHARACTER_WALKING_SPEED);
break;
case SDLK_s:
motion.y = std::max(0.0, motion.y -= CHARACTER_WALKING_SPEED);
break;
case SDLK_d:
motion.x = std::max(0.0, motion.x -= CHARACTER_WALKING_SPEED);
break;
default:
//DOCS: prevents wrong keys screwing with character movement
return;
}
//BUGFIX: reset cardinal direction speed on key release
if (motion.x > 0) {
motion.x = CHARACTER_WALKING_SPEED;
}
else if (motion.x < 0) {
motion.x = -CHARACTER_WALKING_SPEED;
}
if (motion.y > 0) {
motion.y = CHARACTER_WALKING_SPEED;
}
else if (motion.y < 0) {
motion.y = -CHARACTER_WALKING_SPEED;
}
//handle diagonals
if (motion.x != 0 && motion.y != 0) {
motion *= CHARACTER_WALKING_MOD;
}
//set the info
localCharacter->SetMotion(motion);
localCharacter->CorrectSprite();
SendLocalCharacterMovement();
}
//-------------------------
//Direct incoming traffic
//-------------------------
void World::HandlePacket(SerialPacket* const argPacket) {
switch(argPacket->type) {
//heartbeat system
case SerialPacketType::PING:
hPing(static_cast<ServerPacket*>(argPacket));
break;
case SerialPacketType::PONG:
hPong(static_cast<ServerPacket*>(argPacket));
break;
//game server connections
case SerialPacketType::LOGOUT_RESPONSE:
hLogoutResponse(static_cast<ClientPacket*>(argPacket));
break;
case SerialPacketType::DISCONNECT_RESPONSE:
hDisconnectResponse(static_cast<ClientPacket*>(argPacket));
break;
case SerialPacketType::ADMIN_DISCONNECT_FORCED:
hAdminDisconnectForced(static_cast<ClientPacket*>(argPacket));
break;
//map management
case SerialPacketType::REGION_CONTENT:
hRegionContent(static_cast<RegionPacket*>(argPacket));
break;
//character management
case SerialPacketType::CHARACTER_UPDATE:
hCharacterUpdate(static_cast<CharacterPacket*>(argPacket));
break;
case SerialPacketType::CHARACTER_CREATE:
hCharacterCreate(static_cast<CharacterPacket*>(argPacket));
break;
case SerialPacketType::CHARACTER_DELETE:
hCharacterDelete(static_cast<CharacterPacket*>(argPacket));
break;
case SerialPacketType::QUERY_CHARACTER_EXISTS:
hQueryCharacterExists(static_cast<CharacterPacket*>(argPacket));
break;
case SerialPacketType::QUERY_CHARACTER_STATS:
hQueryCharacterStats(static_cast<CharacterPacket*>(argPacket));
break;
case SerialPacketType::QUERY_CHARACTER_LOCATION:
hQueryCharacterLocation(static_cast<CharacterPacket*>(argPacket));
break;
case SerialPacketType::CHARACTER_MOVEMENT:
hCharacterMovement(static_cast<CharacterPacket*>(argPacket));
break;
case SerialPacketType::CHARACTER_ATTACK:
hCharacterAttack(static_cast<CharacterPacket*>(argPacket));
break;
case SerialPacketType::CHARACTER_DAMAGE:
hCharacterDamage(static_cast<CharacterPacket*>(argPacket));
break;
//monster management
case SerialPacketType::MONSTER_CREATE:
hMonsterCreate(static_cast<MonsterPacket*>(argPacket));
break;
case SerialPacketType::MONSTER_DELETE:
hMonsterDelete(static_cast<MonsterPacket*>(argPacket));
break;
case SerialPacketType::QUERY_MONSTER_EXISTS:
hQueryMonsterExists(static_cast<MonsterPacket*>(argPacket));
break;
case SerialPacketType::QUERY_MONSTER_STATS:
hQueryMonsterStats(static_cast<MonsterPacket*>(argPacket));
break;
case SerialPacketType::QUERY_MONSTER_LOCATION:
hQueryMonsterLocation(static_cast<MonsterPacket*>(argPacket));
break;
case SerialPacketType::MONSTER_MOVEMENT:
hMonsterMovement(static_cast<MonsterPacket*>(argPacket));
break;
case SerialPacketType::MONSTER_ATTACK:
hMonsterAttack(static_cast<MonsterPacket*>(argPacket));
break;
case SerialPacketType::MONSTER_DAMAGE:
hMonsterDamage(static_cast<MonsterPacket*>(argPacket));
break;
//chat
case SerialPacketType::TEXT_BROADCAST:
hTextBroadcast(static_cast<TextPacket*>(argPacket));
break;
case SerialPacketType::TEXT_SPEECH:
hTextSpeech(static_cast<TextPacket*>(argPacket));
break;
case SerialPacketType::TEXT_WHISPER:
hTextWhisper(static_cast<TextPacket*>(argPacket));
break;
//general rejection messages
case SerialPacketType::REGION_REJECTION:
case SerialPacketType::CHARACTER_REJECTION:
case SerialPacketType::QUERY_REJECTION:
throw(terminal_error(static_cast<TextPacket*>(argPacket)->text));
break;
case SerialPacketType::SHUTDOWN_REJECTION:
throw(std::runtime_error(static_cast<TextPacket*>(argPacket)->text));
break;
//errors
default: {
std::ostringstream msg;
msg << "Unknown SerialPacketType encountered in World: " << static_cast<int>(argPacket->type);
throw(std::runtime_error(msg.str()));
}
break;
}
}
+79
View File
@@ -0,0 +1,79 @@
/* Copyright: (c) Kayne Ruse 2013-2015
*
* 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 "world.hpp"
#include "channels.hpp"
//-------------------------
//map management
//-------------------------
void World::SendRegionRequest(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);
}
void World::hRegionContent(RegionPacket* const argPacket) {
//replace existing regions
regionPager.UnloadIf([&](Region const& region) -> bool {
return region.GetX() == argPacket->x && region.GetY() == argPacket->y;
});
regionPager.PushRegion(argPacket->region);
//clean up after the serial code
delete argPacket->region;
argPacket->region = nullptr;
}
void World::UpdateMap() {
if (roomIndex == -1) {
return;
}
//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
regionPager.GetContainer()->remove_if([&](Region const& region) -> bool {
return region.GetX() < xStart || region.GetX() > xEnd || region.GetY() < yStart || region.GetY() > yEnd;
});
//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)) {
SendRegionRequest(roomIndex, i, j);
}
}
}
}
+126
View File
@@ -0,0 +1,126 @@
/* Copyright: (c) Kayne Ruse 2013-2015
*
* 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 "world.hpp"
#include "channels.hpp"
#include <iostream>
#include <sstream>
#include <stdexcept>
//-------------------------
//monster management
//-------------------------
void World::hMonsterCreate(MonsterPacket* const argPacket) {
//check for logic errors
if (monsterMap.find(argPacket->monsterIndex) != monsterMap.end()) {
std::ostringstream msg;
msg << "Double monster creation event; ";
msg << "Index: " << argPacket->monsterIndex << "; ";
msg << "Handle: " << argPacket->handle;
throw(std::runtime_error(msg.str()));
}
//ignore monsters from other rooms
if (roomIndex != argPacket->roomIndex) {
//temporary error checking
std::ostringstream msg;
msg << "Monster from the wrong room received: ";
msg << "monsterIndex: " << argPacket->monsterIndex << ", roomIndex: " << argPacket->roomIndex;
throw(std::runtime_error(msg.str()));
}
//implicitly create the element
BaseMonster* monster = &monsterMap[argPacket->monsterIndex];
//fill the monster's info
monster->SetHandle(argPacket->handle);
monster->SetAvatar(argPacket->avatar);
monster->SetBounds(argPacket->bounds);
monster->SetOrigin(argPacket->origin);
monster->SetMotion(argPacket->motion);
//debug
std::cout << "Monster Create, total: " << monsterMap.size() << std::endl;
}
void World::hMonsterDelete(MonsterPacket* const argPacket) {
//ignore if this monster doesn't exist
std::map<int, BaseMonster>::iterator monsterIt = monsterMap.find(argPacket->monsterIndex);
if (monsterIt == monsterMap.end()) {
return;
}
//remove this monster
monsterMap.erase(monsterIt);
//debug
std::cout << "Monster Delete, total: " << monsterMap.size() << std::endl;
}
void World::hQueryMonsterExists(MonsterPacket* const argPacket) {
//ignore monsters in a different room (sub-optimal)
if (argPacket->roomIndex != roomIndex) {
return;
}
//implicitly create the element
BaseMonster* monster = &monsterMap[argPacket->monsterIndex];
//fill the monster's info
monster->SetHandle(argPacket->handle);
monster->SetAvatar(argPacket->avatar);
monster->SetBounds(argPacket->bounds);
monster->SetOrigin(argPacket->origin);
monster->SetMotion(argPacket->motion);
//debug
std::cout << "Monster Query, total: " << monsterMap.size() << std::endl;
}
void World::hQueryMonsterStats(MonsterPacket* const argPacket) {
//TODO: (9) World::hQueryMonsterStats()
}
void World::hQueryMonsterLocation(MonsterPacket* const argPacket) {
//TODO: (9) World::hQueryMonsterLocation()
}
void World::hMonsterMovement(MonsterPacket* const argPacket) {
//ignore if this monster doesn't exist
std::map<int, BaseMonster>::iterator monsterIt = monsterMap.find(argPacket->monsterIndex);
if (monsterIt == monsterMap.end()) {
return;
}
monsterIt->second.SetOrigin(argPacket->origin);
monsterIt->second.SetOrigin(argPacket->motion);
}
void World::hMonsterAttack(MonsterPacket* const argPacket) {
//TODO: (9) World::hMonsterAttack()
}
void World::hMonsterDamage(MonsterPacket* const argPacket) {
//TODO: (9) World::hMonsterDamage()
}
+2 -2
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2013, 2014 /* Copyright: (c) Kayne Ruse 2013-2015
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
@@ -36,7 +36,7 @@ int main(int argc, char* argv[]) {
ConfigUtility::CreateSingleton(); ConfigUtility::CreateSingleton();
UDPNetworkUtility::CreateSingleton(); UDPNetworkUtility::CreateSingleton();
//call the server's routines //call the client's routines
ClientApplication::CreateSingleton(); ClientApplication::CreateSingleton();
ClientApplication& app = ClientApplication::GetSingleton(); ClientApplication& app = ClientApplication::GetSingleton();
+15 -5
View File
@@ -1,6 +1,15 @@
#config #include directories
INCLUDES+=. client_utilities renderable scenes ../common/debugging ../common/gameplay ../common/graphics ../common/map ../common/network ../common/network/packet_types ../common/ui ../common/utilities INCLUDES+=. client_utilities entities gameplay_scenes menu_scenes ../common/debugging ../common/gameplay ../common/graphics ../common/map ../common/network ../common/network/packet_types ../common/ui ../common/utilities
LIBS+=client.a ../libcommon.a -lSDL_net -lwsock32 -liphlpapi -lmingw32 -lSDLmain -lSDL -llua
#libraries
#the order of the $(LIBS) is important, at least for MinGW
LIBS+=client.a ../libcommon.a -lSDL_net
ifeq ($(OS),Windows_NT)
LIBS+=-lwsock32 -liphlpapi -lmingw32
endif
LIBS+=-lSDLmain -lSDL
#flags
CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES)) CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES))
#source #source
@@ -17,8 +26,9 @@ OUT=$(addprefix $(OUTDIR)/,client)
#targets #targets
all: $(OBJ) $(OUT) all: $(OBJ) $(OUT)
$(MAKE) -C client_utilities $(MAKE) -C client_utilities
$(MAKE) -C scenes $(MAKE) -C entities
$(MAKE) -C renderable $(MAKE) -C gameplay_scenes
$(MAKE) -C menu_scenes
$(CXX) $(CXXFLAGS) -o $(OUT) $(OBJ) $(LIBS) $(CXX) $(CXXFLAGS) -o $(OUT) $(OBJ) $(LIBS)
$(OBJ): | $(OBJDIR) $(OBJ): | $(OBJDIR)
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2014 /* Copyright: (c) Kayne Ruse 2013-2015
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2014 /* Copyright: (c) Kayne Ruse 2013-2015
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2013, 2014 /* Copyright: (c) Kayne Ruse 2013-2015
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
@@ -22,9 +22,9 @@
#include "lobby_menu.hpp" #include "lobby_menu.hpp"
#include "channels.hpp" #include "channels.hpp"
#include "utility.hpp"
#include <stdexcept> #include <stdexcept>
#include <sstream>
//------------------------- //-------------------------
//Public access members //Public access members
@@ -100,14 +100,15 @@ void LobbyMenu::FrameEnd() {
} }
void LobbyMenu::Render(SDL_Surface* const screen) { void LobbyMenu::Render(SDL_Surface* const screen) {
//TODO: I need a proper UI system for the entire client and the editor //TODO: (2) I need a proper UI system for the entire client and the editor
//UI //UI
search.DrawTo(screen); search.DrawTo(screen);
join.DrawTo(screen); join.DrawTo(screen);
back.DrawTo(screen); back.DrawTo(screen);
//TODO: draw headers for the server list //TODO: (3) draw headers for the server list
//TODO: (3) ping/delay displayed in the server list
for (int i = 0; i < serverInfo.size(); i++) { for (int i = 0; i < serverInfo.size(); i++) {
//draw the selected server's highlight //draw the selected server's highlight
if (selection == &serverInfo[i]) { if (selection == &serverInfo[i]) {
@@ -123,14 +124,14 @@ void LobbyMenu::Render(SDL_Surface* const screen) {
font.DrawStringTo(serverInfo[i].name, screen, listBox.x, listBox.y + i*listBox.h); font.DrawStringTo(serverInfo[i].name, screen, listBox.x, listBox.y + i*listBox.h);
//draw the player count //draw the player count
font.DrawStringTo(to_string_custom(serverInfo[i].playerCount), screen, listBox.x + listBox.w, listBox.y + i*listBox.h); std::ostringstream msg;
msg << serverInfo[i].playerCount;
font.DrawStringTo(msg.str(), screen, listBox.x + listBox.w, listBox.y + i*listBox.h);
//compatible? //compatible?
if (!serverInfo[i].compatible) { if (!serverInfo[i].compatible) {
font.DrawStringTo("?", screen, listBox.x - font.GetCharW(), listBox.y + i*listBox.h); font.DrawStringTo("?", screen, listBox.x - font.GetCharW(), listBox.y + i*listBox.h);
} }
//TODO: ping/delay?
} }
} }
@@ -190,18 +191,31 @@ void LobbyMenu::KeyUp(SDL_KeyboardEvent const& key) {
void LobbyMenu::HandlePacket(SerialPacket* const argPacket) { void LobbyMenu::HandlePacket(SerialPacket* const argPacket) {
switch(argPacket->type) { switch(argPacket->type) {
//responses
case SerialPacketType::BROADCAST_RESPONSE: case SerialPacketType::BROADCAST_RESPONSE:
HandleBroadcastResponse(static_cast<ServerPacket*>(argPacket)); HandleBroadcastResponse(static_cast<ServerPacket*>(argPacket));
break; break;
case SerialPacketType::JOIN_RESPONSE: case SerialPacketType::JOIN_RESPONSE:
HandleJoinResponse(static_cast<ClientPacket*>(argPacket)); HandleJoinResponse(static_cast<ClientPacket*>(argPacket));
break; break;
case SerialPacketType::LOGIN_RESPONSE:
HandleLoginResponse(static_cast<ClientPacket*>(argPacket));
break;
//rejections
case SerialPacketType::JOIN_REJECTION: case SerialPacketType::JOIN_REJECTION:
HandleJoinRejection(static_cast<TextPacket*>(argPacket)); HandleJoinRejection(static_cast<TextPacket*>(argPacket));
break; break;
case SerialPacketType::LOGIN_REJECTION:
HandleLoginRejection(static_cast<TextPacket*>(argPacket));
break;
//handle errors //handle errors
default: default: {
throw(std::runtime_error(std::string() + "Unknown SerialPacketType encountered in LobbyMenu: " + to_string_custom(static_cast<int>(argPacket->type)) )); std::ostringstream msg;
msg << "Unknown SerialPacketType encountered in LobbyMenu: " << static_cast<int>(argPacket->type);
throw(std::runtime_error( msg.str() ));
}
break; break;
} }
} }
@@ -222,14 +236,28 @@ void LobbyMenu::HandleBroadcastResponse(ServerPacket* const argPacket) {
} }
void LobbyMenu::HandleJoinResponse(ClientPacket* const argPacket) { void LobbyMenu::HandleJoinResponse(ClientPacket* const argPacket) {
//save the server's data
clientIndex = argPacket->clientIndex; clientIndex = argPacket->clientIndex;
accountIndex = argPacket->accountIndex;
network.Bind(argPacket->srcAddress, Channels::SERVER); network.Bind(argPacket->srcAddress, Channels::SERVER);
SetNextScene(SceneList::INWORLD);
//request login data
SendLoginRequest();
}
void LobbyMenu::HandleLoginResponse(ClientPacket* const argPacket) {
if (argPacket->clientIndex != clientIndex) {
throw(std::runtime_error("Client index invalid during login"));
}
accountIndex = argPacket->accountIndex;
SetNextScene(SceneList::WORLD);
} }
void LobbyMenu::HandleJoinRejection(TextPacket* const argPacket) { void LobbyMenu::HandleJoinRejection(TextPacket* const argPacket) {
//TODO: Better output for join rejection //TODO: (9) LobbyMenu::HandleJoinRejection()
}
void LobbyMenu::HandleLoginRejection(TextPacket* const argPacket) {
//TODO: (9) LobbyMenu::HandleLoginRejection
} }
//------------------------- //-------------------------
@@ -251,9 +279,18 @@ void LobbyMenu::SendJoinRequest() {
//pack the packet //pack the packet
ClientPacket packet; ClientPacket packet;
packet.type = SerialPacketType::JOIN_REQUEST; packet.type = SerialPacketType::JOIN_REQUEST;
strncpy(packet.username, config["client.username"].c_str(), PACKET_STRING_SIZE);
//join the selected server //join the selected server
network.SendTo(selection->address, &packet); network.SendTo(selection->address, &packet);
selection = nullptr; selection = nullptr;
} }
void LobbyMenu::SendLoginRequest() {
//NOTE: high cohesion
ClientPacket packet;
packet.type = SerialPacketType::LOGIN_REQUEST;
packet.clientIndex = clientIndex;
strncpy(packet.username, config["client.username"].c_str(), PACKET_STRING_SIZE);
network.SendTo(Channels::SERVER, &packet);
}
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2013, 2014 /* Copyright: (c) Kayne Ruse 2013-2015
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
@@ -63,11 +63,14 @@ protected:
void HandlePacket(SerialPacket* const); void HandlePacket(SerialPacket* const);
void HandleBroadcastResponse(ServerPacket* const); void HandleBroadcastResponse(ServerPacket* const);
void HandleJoinResponse(ClientPacket* const); void HandleJoinResponse(ClientPacket* const);
void HandleLoginResponse(ClientPacket* const);
void HandleJoinRejection(TextPacket* const); void HandleJoinRejection(TextPacket* const);
void HandleLoginRejection(TextPacket* const);
//server control //server control
void SendBroadcastRequest(); void SendBroadcastRequest();
void SendJoinRequest(); void SendJoinRequest();
void SendLoginRequest();
//shared parameters //shared parameters
ConfigUtility& config = ConfigUtility::GetSingleton(); ConfigUtility& config = ConfigUtility::GetSingleton();
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2013, 2014 /* Copyright: (c) Kayne Ruse 2013-2015
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
@@ -84,6 +84,11 @@ void MainMenu::Render(SDL_Surface* const screen) {
startButton.DrawTo(screen); startButton.DrawTo(screen);
optionsButton.DrawTo(screen); optionsButton.DrawTo(screen);
quitButton.DrawTo(screen); quitButton.DrawTo(screen);
//text
font.DrawStringTo("Thanks for playing!", screen, 50, screen->h - 50 - image.GetClipH() * 2);
font.DrawStringTo("You can get the latest version at: ", screen, 50, screen->h - 50 - image.GetClipH() * 1);
font.DrawStringTo("krgamestudios.com", screen, 50, screen->h - 50 - image.GetClipH() * 0);
} }
//------------------------- //-------------------------
@@ -103,7 +108,7 @@ void MainMenu::MouseButtonDown(SDL_MouseButtonEvent const& button) {
} }
void MainMenu::MouseButtonUp(SDL_MouseButtonEvent const& button) { void MainMenu::MouseButtonUp(SDL_MouseButtonEvent const& button) {
//TODO: Buttons should only register as "selected" when the left button is used //TODO: (2) Buttons should only register as "selected" when the left button is used
if (startButton.MouseButtonUp(button) == Button::State::HOVER) { if (startButton.MouseButtonUp(button) == Button::State::HOVER) {
SetNextScene(SceneList::LOBBYMENU); SetNextScene(SceneList::LOBBYMENU);
} }
@@ -120,5 +125,9 @@ void MainMenu::KeyDown(SDL_KeyboardEvent const& key) {
} }
void MainMenu::KeyUp(SDL_KeyboardEvent const& key) { void MainMenu::KeyUp(SDL_KeyboardEvent const& key) {
// switch(key.keysym.sym) {
case SDLK_ESCAPE:
QuitEvent();
break;
}
} }
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2013, 2014 /* Copyright: (c) Kayne Ruse 2013-2015
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
@@ -1,5 +1,5 @@
#config #config
INCLUDES+=. .. ../renderable ../../common/gameplay ../../common/graphics ../../common/map ../../common/network ../../common/network/packet_types ../../common/ui ../../common/utilities INCLUDES+=. .. ../../common/graphics ../../common/map ../../common/network ../../common/network/packet_types ../../common/ui ../../common/utilities
LIBS+= LIBS+=
CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES)) CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES))
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2013, 2014 /* Copyright: (c) Kayne Ruse 2013-2015
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2013, 2014 /* Copyright: (c) Kayne Ruse 2013-2015
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
@@ -28,7 +28,7 @@
#include "raster_font.hpp" #include "raster_font.hpp"
#include "button.hpp" #include "button.hpp"
//TODO: The options screen needs to be USED //NOTE: The options screen needs to be USED
class OptionsMenu : public BaseScene { class OptionsMenu : public BaseScene {
public: public:
//Public access members //Public access members
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2013, 2014 /* Copyright: (c) Kayne Ruse 2013-2015
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2013, 2014 /* Copyright: (c) Kayne Ruse 2013-2015
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
+2 -2
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2013, 2014 /* Copyright: (c) Kayne Ruse 2013-2015
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
@@ -33,7 +33,7 @@ enum class SceneList {
MAINMENU, MAINMENU,
OPTIONSMENU, OPTIONSMENU,
LOBBYMENU, LOBBYMENU,
INWORLD, WORLD,
DISCONNECTEDSCREEN, DISCONNECTEDSCREEN,
}; };
-538
View File
@@ -1,538 +0,0 @@
/* 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 "config_utility.hpp"
#include <stdexcept>
#include <algorithm>
#include <cmath>
#include <iostream>
//-------------------------
//Public access members
//-------------------------
InWorld::InWorld(int* const argClientIndex, int* const argAccountIndex):
clientIndex(*argClientIndex),
accountIndex(*argAccountIndex)
{
ConfigUtility& config = ConfigUtility::GetSingleton();
//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?
//TODO: Tile size and tile sheet should be loaded elsewhere
tileSheet.Load(config["dir.tilesets"] + "overworld.bmp", 32, 32);
//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);
//request a sync
RequestSynchronize();
//debug
//
}
InWorld::~InWorld() {
//
}
//-------------------------
//Frame loop
//-------------------------
void InWorld::FrameStart() {
//
}
void InWorld::Update() {
//suck in and process all waiting packets
SerialPacket* packetBuffer = reinterpret_cast<SerialPacket*>(new char[MAX_PACKET_SIZE]);
while(network.Receive(packetBuffer)) {
HandlePacket(packetBuffer);
}
delete reinterpret_cast<char*>(packetBuffer);
//update the characters
for (auto& it : characterMap) {
it.second.Update();
}
//check the map
UpdateMap();
//skip the rest
if (!localCharacter) {
return;
}
//check for collisions with the map
BoundingBox wallBounds = {0, 0, tileSheet.GetTileW(), tileSheet.GetTileH()};
const int xCount = localCharacter->GetBounds().w / wallBounds.w + 1;
const int yCount = localCharacter->GetBounds().h / wallBounds.h + 1;
for (int i = -1; i <= xCount; ++i) {
for (int j = -1; j <= yCount; ++j) {
//set the wall's position
wallBounds.x = wallBounds.w * i + snapToBase((double)wallBounds.w, localCharacter->GetOrigin().x);
wallBounds.y = wallBounds.h * j + snapToBase((double)wallBounds.h, localCharacter->GetOrigin().y);
if (!regionPager.GetSolid(wallBounds.x / wallBounds.w, wallBounds.y / wallBounds.h)) {
continue;
}
if ((localCharacter->GetOrigin() + localCharacter->GetBounds()).CheckOverlap(wallBounds)) {
localCharacter->SetOrigin(localCharacter->GetOrigin() - (localCharacter->GetMotion()));
localCharacter->SetMotion({0,0});
localCharacter->CorrectSprite();
SendPlayerUpdate();
}
}
}
//update the camera
camera.x = localCharacter->GetOrigin().x - camera.marginX;
camera.y = localCharacter->GetOrigin().y - camera.marginY;
//check the connection
if (Clock::now() - lastBeat > std::chrono::seconds(3)) {
if (attemptedBeats > 2) {
RequestDisconnect();
SetNextScene(SceneList::DISCONNECTEDSCREEN);
ConfigUtility::GetSingleton()["client.disconnectMessage"] = "Error: Lost connection to the server";
}
ServerPacket newPacket;
newPacket.type = SerialPacketType::PING;
network.SendTo(Channels::SERVER, &newPacket);
attemptedBeats++;
lastBeat = Clock::now();
}
}
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) {
//BUG: #29 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::QUIT);
}
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) {
if (!localCharacter) {
return;
}
//hotkeys
switch(key.keysym.sym) {
case SDLK_ESCAPE:
RequestDisconnect();
break;
}
//player movement
Vector2 motion = localCharacter->GetMotion();
switch(key.keysym.sym) {
case SDLK_LEFT:
motion.x -= CHARACTER_WALKING_SPEED;
break;
case SDLK_RIGHT:
motion.x += CHARACTER_WALKING_SPEED;
break;
case SDLK_UP:
motion.y -= CHARACTER_WALKING_SPEED;
break;
case SDLK_DOWN:
motion.y += CHARACTER_WALKING_SPEED;
break;
default:
return;
}
localCharacter->SetMotion(motion);
localCharacter->CorrectSprite();
SendPlayerUpdate();
}
void InWorld::KeyUp(SDL_KeyboardEvent const& key) {
if (!localCharacter) {
return;
}
//player movement
Vector2 motion = localCharacter->GetMotion();
switch(key.keysym.sym) {
//NOTE: The use of min/max here are to prevent awkward movements
case SDLK_LEFT:
motion.x = std::min(motion.x + CHARACTER_WALKING_SPEED, 0.0);
break;
case SDLK_RIGHT:
motion.x = std::max(motion.x - CHARACTER_WALKING_SPEED, 0.0);
break;
case SDLK_UP:
motion.y = std::min(motion.y + CHARACTER_WALKING_SPEED, 0.0);
break;
case SDLK_DOWN:
motion.y = std::max(motion.y - CHARACTER_WALKING_SPEED, 0.0);
break;
default:
return;
}
localCharacter->SetMotion(motion);
localCharacter->CorrectSprite();
SendPlayerUpdate();
}
//-------------------------
//Network handlers
//-------------------------
void InWorld::HandlePacket(SerialPacket* const argPacket) {
switch(argPacket->type) {
case SerialPacketType::PING:
HandlePing(static_cast<ServerPacket*>(argPacket));
break;
case SerialPacketType::PONG:
HandlePong(static_cast<ServerPacket*>(argPacket));
break;
case SerialPacketType::DISCONNECT:
HandleDisconnect(static_cast<ClientPacket*>(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::CHARACTER_REJECTION:
HandleCharacterRejection(static_cast<TextPacket*>(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::HandlePing(ServerPacket* const argPacket) {
ServerPacket newPacket;
newPacket.type = SerialPacketType::PONG;
network.SendTo(argPacket->srcAddress, &newPacket);
}
void InWorld::HandlePong(ServerPacket* const argPacket) {
if (network.GetIPAddress(Channels::SERVER)->host != argPacket->srcAddress.host) {
throw(std::runtime_error("Heartbeat message received from unknown source"));
}
attemptedBeats = 0;
lastBeat = Clock::now();
}
void InWorld::HandleDisconnect(ClientPacket* const argPacket) {
//TODO: More needed in the disconnection
SetNextScene(SceneList::DISCONNECTEDSCREEN);
ConfigUtility::GetSingleton()["client.disconnectMessage"] = "You have been disconnected";
}
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
BaseCharacter& newCharacter = characterMap[argPacket->characterIndex];
//fill out the character's members
newCharacter.SetHandle(argPacket->handle);
newCharacter.SetAvatar(argPacket->avatar);
newCharacter.GetSprite()->LoadSurface(ConfigUtility::GetSingleton()["dir.sprites"] + newCharacter.GetAvatar(), 4, 4);
newCharacter.SetOrigin(argPacket->origin);
newCharacter.SetMotion(argPacket->motion);
newCharacter.SetBounds({
CHARACTER_BOUNDS_X,
CHARACTER_BOUNDS_Y,
CHARACTER_BOUNDS_WIDTH,
CHARACTER_BOUNDS_HEIGHT
});
// (*newCharacter.GetBaseStats()) = argPacket->stats;
//bookkeeping code
newCharacter.CorrectSprite();
//catch this client's player object
if (argPacket->accountIndex == accountIndex && !localCharacter) {
characterIndex = argPacket->characterIndex;
localCharacter = &newCharacter;
//setup the camera
camera.width = GetScreen()->w;
camera.height = GetScreen()->h;
//center on the player's character
camera.marginX = (GetScreen()->w / 2 - localCharacter->GetSprite()->GetImage()->GetClipW() / 2);
camera.marginY = (GetScreen()->h / 2 - localCharacter->GetSprite()->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;
}
BaseCharacter& character = characterMap[argPacket->characterIndex];
//other characters moving
if (argPacket->characterIndex != characterIndex) {
character.SetOrigin(argPacket->origin);
character.SetMotion(argPacket->motion);
character.CorrectSprite();
}
}
void InWorld::HandleCharacterRejection(TextPacket* const argPacket) {
RequestDisconnect();
SetNextScene(SceneList::DISCONNECTEDSCREEN);
ConfigUtility& config = ConfigUtility::GetSingleton();
config["client.disconnectMessage"] = "Error: ";
config["client.disconnectMessage"] += argPacket->text;
}
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;
//TODO: location, range for sync request
network.SendTo(Channels::SERVER, &newPacket);
}
void InWorld::SendPlayerUpdate() {
CharacterPacket newPacket;
//pack the packet
newPacket.type = SerialPacketType::CHARACTER_UPDATE;
newPacket.characterIndex = characterIndex;
//NOTE: omitting the handle and avatar here
newPacket.accountIndex = accountIndex;
newPacket.roomIndex = 0; //TODO: room index
newPacket.origin = localCharacter->GetOrigin();
newPacket.motion = localCharacter->GetMotion();
// newPacket.stats = *localCharacter->GetBaseStats();
//TODO: gameplay components: equipment, items, buffs, 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 of 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);
}
}
}
}
+3 -3
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2014 /* Copyright: (c) Kayne Ruse 2013-2015
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
@@ -39,7 +39,7 @@ void Timer::Stop() {
std::ostream& operator<<(std::ostream& os, Timer& t) { std::ostream& operator<<(std::ostream& os, Timer& t) {
os << t.GetName() << ": "; os << t.GetName() << ": ";
os << std::chrono::duration_cast<std::chrono::milliseconds>(t.GetTime()).count(); os << std::chrono::duration_cast<std::chrono::microseconds>(t.GetTime()).count();
os << "ms"; os << "us";
return os; return os;
} }
+3 -3
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2014 /* Copyright: (c) Kayne Ruse 2013-2015
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
@@ -34,8 +34,8 @@ public:
Timer(std::string s); Timer(std::string s);
~Timer() = default; ~Timer() = default;
inline void Start(); void Start();
inline void Stop(); void Stop();
//accessors and mutators //accessors and mutators
Clock::duration GetTime() { return timeSpan; } Clock::duration GetTime() { return timeSpan; }
+5 -1
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2014 /* Copyright: (c) Kayne Ruse 2013-2015
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
@@ -35,4 +35,8 @@ constexpr int CHARACTER_BOUNDS_Y = 16;
constexpr int CHARACTER_BOUNDS_WIDTH = 32; constexpr int CHARACTER_BOUNDS_WIDTH = 32;
constexpr int CHARACTER_BOUNDS_HEIGHT = 32; constexpr int CHARACTER_BOUNDS_HEIGHT = 32;
//the character's sprite format
constexpr int CHARACTER_CELLS_X = 4;
constexpr int CHARACTER_CELLS_Y = 4;
#endif #endif
+1 -1
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2013, 2014 /* Copyright: (c) Kayne Ruse 2013-2015
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
+1 -1
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2013, 2014 /* Copyright: (c) Kayne Ruse 2013-2015
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
+1 -1
View File
@@ -1,5 +1,5 @@
#config #config
INCLUDES+=. INCLUDES+=. ../map
LIBS+= LIBS+=
CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES)) CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES))
+1 -1
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2013, 2014 /* Copyright: (c) Kayne Ruse 2013-2015
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
+1 -1
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2013, 2014 /* Copyright: (c) Kayne Ruse 2013-2015
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2014 /* Copyright: (c) Kayne Ruse 2013-2015
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2014 /* Copyright: (c) Kayne Ruse 2013-2015
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
+1 -1
View File
@@ -1,5 +1,5 @@
#config #config
INCLUDES+=. ../graphics ../utilities INCLUDES+=. ../utilities
LIBS+= LIBS+=
CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES)) CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES))
+26 -2
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2014 /* Copyright: (c) Kayne Ruse 2013-2015
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
@@ -21,9 +21,9 @@
*/ */
#include "region.hpp" #include "region.hpp"
#include <stdexcept>
#include <cmath> #include <cmath>
#include <cstring> #include <cstring>
#include <stdexcept>
int snapToBase(int base, int x) { int snapToBase(int base, int x) {
return floor((double)x / base) * base; return floor((double)x / base) * base;
@@ -42,17 +42,41 @@ Region::Region(Region const& rhs): x(rhs.x), y(rhs.y) {
} }
Region::type_t Region::SetTile(int x, int y, int z, type_t v) { Region::type_t Region::SetTile(int x, int y, int z, type_t v) {
if (x < 0 || y < 0 || z < 0 || x >= REGION_WIDTH || y >= REGION_HEIGHT || z >= REGION_DEPTH) {
throw(std::out_of_range("Region::SetTile() argument out of range"));
}
return tiles[x][y][z] = v; return tiles[x][y][z] = v;
} }
Region::type_t Region::GetTile(int x, int y, int z) { Region::type_t Region::GetTile(int x, int y, int z) {
if (x < 0 || y < 0 || z < 0 || x >= REGION_WIDTH || y >= REGION_HEIGHT || z >= REGION_DEPTH) {
throw(std::out_of_range("Region::GetTile() argument out of range"));
}
return tiles[x][y][z]; return tiles[x][y][z];
} }
bool Region::SetSolid(int x, int y, bool b) { bool Region::SetSolid(int x, int y, bool b) {
if (x < 0 || y < 0 || x >= REGION_WIDTH || y >= REGION_HEIGHT) {
throw(std::out_of_range("Region::SetSolid() argument out of range"));
}
return solid[x * REGION_WIDTH + y] = b; return solid[x * REGION_WIDTH + y] = b;
} }
bool Region::GetSolid(int x, int y) { bool Region::GetSolid(int x, int y) {
if (x < 0 || y < 0 || x >= REGION_WIDTH || y >= REGION_HEIGHT) {
throw(std::out_of_range("Region::GetSolid() argument out of range"));
}
return solid[x * REGION_WIDTH + y]; return solid[x * REGION_WIDTH + y];
}
int Region::GetX() const {
return x;
}
int Region::GetY() const {
return y;
}
std::bitset<REGION_WIDTH*REGION_HEIGHT>* Region::GetSolidBitset() {
return &solid;
} }
+4 -4
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2014 /* Copyright: (c) Kayne Ruse 2013-2015
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
@@ -48,10 +48,10 @@ public:
bool GetSolid(int x, int y); bool GetSolid(int x, int y);
//accessors //accessors
int GetX() const { return x; } int GetX() const;
int GetY() const { return y; } int GetY() const;
std::bitset<REGION_WIDTH*REGION_HEIGHT>* GetSolidBitset() { return &solid; } std::bitset<REGION_WIDTH*REGION_HEIGHT>* GetSolidBitset();
private: private:
const int x; const int x;
const int y; const int y;
+3 -1
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2014 /* Copyright: (c) Kayne Ruse 2013-2015
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
@@ -85,6 +85,8 @@ static const luaL_Reg regionLib[] = {
{"GetSolid",getSolid}, {"GetSolid",getSolid},
{"GetX",getX}, {"GetX",getX},
{"GetY",getY}, {"GetY",getY},
//the global macros
{"GetWidth",getWidth}, {"GetWidth",getWidth},
{"GetHeight",getHeight}, {"GetHeight",getHeight},
{"GetDepth",getDepth}, {"GetDepth",getDepth},
+3 -3
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2014 /* Copyright: (c) Kayne Ruse 2013-2015
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
@@ -22,9 +22,9 @@
#ifndef REGIONAPI_HPP_ #ifndef REGIONAPI_HPP_
#define REGIONAPI_HPP_ #define REGIONAPI_HPP_
#include "lua/lua.hpp" #include "lua.hpp"
#define TORTUGA_REGION_NAME "Region" #define TORTUGA_REGION_API "region"
LUAMOD_API int openRegionAPI(lua_State* L); LUAMOD_API int openRegionAPI(lua_State* L);
#endif #endif
+28 -2
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2014 /* Copyright: (c) Kayne Ruse 2013-2015
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
@@ -25,6 +25,7 @@
#include "region.hpp" #include "region.hpp"
//DOCS: These glue functions simply wrap RegionPagerLua's methods //DOCS: These glue functions simply wrap RegionPagerLua's methods
//NOTE: zero indexing is used here, but not in the region API
static int setTile(lua_State* L) { static int setTile(lua_State* L) {
RegionPagerLua* pager = reinterpret_cast<RegionPagerLua*>(lua_touserdata(L, 1)); RegionPagerLua* pager = reinterpret_cast<RegionPagerLua*>(lua_touserdata(L, 1));
@@ -84,7 +85,22 @@ static int createRegion(lua_State* L) {
static int unloadRegion(lua_State* L) { static int unloadRegion(lua_State* L) {
RegionPagerLua* pager = reinterpret_cast<RegionPagerLua*>(lua_touserdata(L, 1)); RegionPagerLua* pager = reinterpret_cast<RegionPagerLua*>(lua_touserdata(L, 1));
pager->UnloadRegion(lua_tointeger(L, 2), lua_tointeger(L, 3));
//two argument types: coords & the region itself
switch(lua_type(L, 2)) {
case LUA_TNUMBER:
pager->UnloadIf([&](Region const& region) -> bool {
int x = lua_tointeger(L, 2);
int y = lua_tointeger(L, 3);
return region.GetX() == x && region.GetY() == y;
});
break;
case LUA_TLIGHTUSERDATA:
pager->UnloadIf([&](Region const& region) -> bool {
return (&region) == lua_touserdata(L, 2);
});
break;
}
return 0; return 0;
} }
@@ -116,6 +132,13 @@ static int setOnUnload(lua_State* L) {
return 0; return 0;
} }
//debugging
static int containerSize(lua_State* L) {
RegionPagerLua* pager = static_cast<RegionPagerLua*>(lua_touserdata(L, 1));
lua_pushinteger(L, pager->GetContainer()->size());
return 1;
}
static const luaL_Reg regionPagerLib[] = { static const luaL_Reg regionPagerLib[] = {
//curry //curry
{"SetTile", setTile}, {"SetTile", setTile},
@@ -136,6 +159,9 @@ static const luaL_Reg regionPagerLib[] = {
{"SetOnCreate",setOnCreate}, {"SetOnCreate",setOnCreate},
{"SetOnUnload",setOnUnload}, {"SetOnUnload",setOnUnload},
//debugging
{"ContainerSize", containerSize},
//sentinel //sentinel
{nullptr, nullptr} {nullptr, nullptr}
}; };
+3 -3
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2014 /* Copyright: (c) Kayne Ruse 2013-2015
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
@@ -22,9 +22,9 @@
#ifndef REGIONPAGERAPI_HPP_ #ifndef REGIONPAGERAPI_HPP_
#define REGIONPAGERAPI_HPP_ #define REGIONPAGERAPI_HPP_
#include "lua/lua.hpp" #include "lua.hpp"
#define TORTUGA_REGION_PAGER_NAME "RegionPager" #define TORTUGA_REGION_PAGER_API "region_pager"
LUAMOD_API int openRegionPagerAPI(lua_State* L); LUAMOD_API int openRegionPagerAPI(lua_State* L);
#endif #endif
+11 -5
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2014 /* Copyright: (c) Kayne Ruse 2013-2015
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
@@ -24,6 +24,10 @@
#include <stdexcept> #include <stdexcept>
#include <algorithm> #include <algorithm>
RegionPagerBase::~RegionPagerBase() {
UnloadAll();
};
Region::type_t RegionPagerBase::SetTile(int x, int y, int z, Region::type_t v) { Region::type_t RegionPagerBase::SetTile(int x, int y, int z, Region::type_t v) {
Region* ptr = GetRegion(x, y); Region* ptr = GetRegion(x, y);
return ptr->SetTile(x - ptr->GetX(), y - ptr->GetY(), z, v); return ptr->SetTile(x - ptr->GetX(), y - ptr->GetY(), z, v);
@@ -88,12 +92,14 @@ Region* RegionPagerBase::CreateRegion(int x, int y) {
return &regionList.front(); return &regionList.front();
} }
void RegionPagerBase::UnloadRegion(int x, int y) { void RegionPagerBase::UnloadIf(std::function<bool(Region const&)> fn) {
regionList.remove_if([x, y](Region& region) -> bool { regionList.remove_if(fn);
return region.GetX() == x && region.GetY() == y;
});
} }
void RegionPagerBase::UnloadAll() { void RegionPagerBase::UnloadAll() {
regionList.clear(); regionList.clear();
}
std::list<Region>* RegionPagerBase::GetContainer() {
return &regionList;
} }
+5 -4
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2014 /* Copyright: (c) Kayne Ruse 2013-2015
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
@@ -24,12 +24,13 @@
#include "region.hpp" #include "region.hpp"
#include <functional>
#include <list> #include <list>
class RegionPagerBase { class RegionPagerBase {
public: public:
RegionPagerBase() = default; RegionPagerBase() = default;
virtual ~RegionPagerBase() { UnloadAll(); }; virtual ~RegionPagerBase();
//tile manipulation //tile manipulation
virtual Region::type_t SetTile(int x, int y, int z, Region::type_t v); virtual Region::type_t SetTile(int x, int y, int z, Region::type_t v);
@@ -47,12 +48,12 @@ public:
virtual Region* LoadRegion(int x, int y); virtual Region* LoadRegion(int x, int y);
virtual Region* SaveRegion(int x, int y); virtual Region* SaveRegion(int x, int y);
virtual Region* CreateRegion(int x, int y); virtual Region* CreateRegion(int x, int y);
virtual void UnloadRegion(int x, int y);
virtual void UnloadIf(std::function<bool(Region const&)> fn);
virtual void UnloadAll(); virtual void UnloadAll();
//accessors & mutators //accessors & mutators
std::list<Region>* GetContainer() { return &regionList; } std::list<Region>* GetContainer();
protected: protected:
std::list<Region> regionList; std::list<Region> regionList;
}; };
+25 -4
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2014 /* Copyright: (c) Kayne Ruse 2013-2015
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
@@ -23,6 +23,20 @@
#include <stdexcept> #include <stdexcept>
//DOCS: Load, Save and Create fail unless the lua function has been set
//DOCS: UnloadIf and UnloadAll will still continue without the function set
RegionPagerLua::~RegionPagerLua() {
//unload all regions
UnloadAll();
//clear any stored functions
luaL_unref(lua, LUA_REGISTRYINDEX, loadRef);
luaL_unref(lua, LUA_REGISTRYINDEX, saveRef);
luaL_unref(lua, LUA_REGISTRYINDEX, createRef);
luaL_unref(lua, LUA_REGISTRYINDEX, unloadRef);
}
//return the loaded region, or nullptr on failure
Region* RegionPagerLua::LoadRegion(int x, int y) { Region* RegionPagerLua::LoadRegion(int x, int y) {
//get the pager's function from the registry //get the pager's function from the registry
lua_rawgeti(lua, LUA_REGISTRYINDEX, loadRef); lua_rawgeti(lua, LUA_REGISTRYINDEX, loadRef);
@@ -54,6 +68,7 @@ Region* RegionPagerLua::LoadRegion(int x, int y) {
} }
} }
//return the saved region, or nullptr on failure
Region* RegionPagerLua::SaveRegion(int x, int y) { Region* RegionPagerLua::SaveRegion(int x, int y) {
//get the pager's function from the registry //get the pager's function from the registry
lua_rawgeti(lua, LUA_REGISTRYINDEX, saveRef); lua_rawgeti(lua, LUA_REGISTRYINDEX, saveRef);
@@ -88,6 +103,7 @@ Region* RegionPagerLua::SaveRegion(int x, int y) {
} }
} }
//return the created region, or nullptr on failure
Region* RegionPagerLua::CreateRegion(int x, int y) { Region* RegionPagerLua::CreateRegion(int x, int y) {
if (FindRegion(x, y)) { if (FindRegion(x, y)) {
throw(std::logic_error("Cannot overwrite an existing region")); throw(std::logic_error("Cannot overwrite an existing region"));
@@ -116,23 +132,26 @@ Region* RegionPagerLua::CreateRegion(int x, int y) {
return &regionList.front(); return &regionList.front();
} }
void RegionPagerLua::UnloadRegion(int x, int y) { //no return
void RegionPagerLua::UnloadIf(std::function<bool(Region const&)> fn) {
//get the pager's function from the registry //get the pager's function from the registry
lua_rawgeti(lua, LUA_REGISTRYINDEX, unloadRef); lua_rawgeti(lua, LUA_REGISTRYINDEX, unloadRef);
//check if this function is available //check if this function is available
if (lua_isnil(lua, -1)) { if (lua_isnil(lua, -1)) {
lua_pop(lua, 1); lua_pop(lua, 1);
//remove the regions anyway
regionList.remove_if(fn);
return; return;
} }
//run each region through this lambda //run each region through this lambda
regionList.remove_if([&](Region& region) -> bool { regionList.remove_if([&](Region& region) -> bool {
if (region.GetX() == x && region.GetY() == y) { if (fn(region)) {
//push a copy of the function onto the stack with the region //push a copy of the function onto the stack with the region
lua_pushvalue(lua, -1); lua_pushvalue(lua, -1);
lua_pushlightuserdata(lua, &region); lua_pushlightuserdata(lua, static_cast<void*>(&region));
//call the function, 1 arg, 0 return //call the function, 1 arg, 0 return
if (lua_pcall(lua, 1, 0, 0) != LUA_OK) { if (lua_pcall(lua, 1, 0, 0) != LUA_OK) {
@@ -157,6 +176,8 @@ void RegionPagerLua::UnloadAll() {
//check if this function is available //check if this function is available
if (lua_isnil(lua, -1)) { if (lua_isnil(lua, -1)) {
lua_pop(lua, 1); lua_pop(lua, 1);
//remove the regions anyway
regionList.clear();
return; return;
} }
+5 -4
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2014 /* Copyright: (c) Kayne Ruse 2013-2015
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
@@ -24,21 +24,22 @@
#include "region_pager_base.hpp" #include "region_pager_base.hpp"
#include "lua/lua.hpp" #include "lua.hpp"
#include <functional>
#include <string> #include <string>
class RegionPagerLua : public RegionPagerBase { class RegionPagerLua : public RegionPagerBase {
public: public:
RegionPagerLua() = default; RegionPagerLua() = default;
~RegionPagerLua() = default; ~RegionPagerLua();
//region manipulation //region manipulation
Region* LoadRegion(int x, int y) override; Region* LoadRegion(int x, int y) override;
Region* SaveRegion(int x, int y) override; Region* SaveRegion(int x, int y) override;
Region* CreateRegion(int x, int y) override; Region* CreateRegion(int x, int y) override;
void UnloadRegion(int x, int y) override;
void UnloadIf(std::function<bool(Region const&)> fn) override;
void UnloadAll() override; void UnloadAll() override;
//accessors & mutators //accessors & mutators
-75
View File
@@ -1,75 +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 "tile_sheet_api.hpp"
#include "tile_sheet.hpp"
static int load(lua_State* L) {
TileSheet* sheet = reinterpret_cast<TileSheet*>(lua_touserdata(L, 1));
sheet->Load(lua_tostring(L, 2), lua_tointeger(L, 3), lua_tointeger(L, 4));
return 0;
}
static int unload(lua_State* L) {
TileSheet* sheet = reinterpret_cast<TileSheet*>(lua_touserdata(L, 1));
sheet->Unload();
return 0;
}
static int getXCount(lua_State* L) {
TileSheet* sheet = reinterpret_cast<TileSheet*>(lua_touserdata(L, 1));
lua_pushinteger(L, sheet->GetXCount());
return 1;
}
static int getYCount(lua_State* L) {
TileSheet* sheet = reinterpret_cast<TileSheet*>(lua_touserdata(L, 1));
lua_pushinteger(L, sheet->GetYCount());
return 1;
}
static int getTileW(lua_State* L) {
TileSheet* sheet = reinterpret_cast<TileSheet*>(lua_touserdata(L, 1));
lua_pushinteger(L, sheet->GetTileW());
return 1;
}
static int getTileH(lua_State* L) {
TileSheet* sheet = reinterpret_cast<TileSheet*>(lua_touserdata(L, 1));
lua_pushinteger(L, sheet->GetTileH());
return 1;
}
static const luaL_Reg tileSheetLib[] = {
{"Load",load},
{"Unload",unload},
{"GetXCount",getXCount},
{"GetYCount",getYCount},
{"GetTileW",getTileW},
{"GetTileH",getTileH},
{nullptr, nullptr}
};
LUAMOD_API int openTileSheetAPI(lua_State* L) {
luaL_newlib(L, tileSheetLib);
return 1;
}
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2014 /* Copyright: (c) Kayne Ruse 2013-2015
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
@@ -23,8 +23,6 @@
#include "serial_utility.hpp" #include "serial_utility.hpp"
#include "serial_statistics.hpp"
void serializeCharacter(void* buffer, CharacterPacket* packet) { void serializeCharacter(void* buffer, CharacterPacket* packet) {
serialCopy(&buffer, &packet->type, sizeof(SerialPacketType)); serialCopy(&buffer, &packet->type, sizeof(SerialPacketType));
@@ -38,13 +36,17 @@ void serializeCharacter(void* buffer, CharacterPacket* packet) {
//location //location
serialCopy(&buffer, &packet->roomIndex, sizeof(int)); serialCopy(&buffer, &packet->roomIndex, sizeof(int));
serialCopy(&buffer, &packet->origin.x, sizeof(double)); serialCopy(&buffer, &packet->origin.x, sizeof(double));
serialCopy(&buffer, &packet->origin.y, sizeof(double)); serialCopy(&buffer, &packet->origin.y, sizeof(double));
serialCopy(&buffer, &packet->motion.x, sizeof(double)); serialCopy(&buffer, &packet->motion.x, sizeof(double));
serialCopy(&buffer, &packet->motion.y, sizeof(double)); serialCopy(&buffer, &packet->motion.y, sizeof(double));
//stats structure serialCopy(&buffer, &packet->bounds.x, sizeof(int));
serializeStatistics(&buffer, &packet->stats); serialCopy(&buffer, &packet->bounds.y, sizeof(int));
serialCopy(&buffer, &packet->bounds.w, sizeof(int));
serialCopy(&buffer, &packet->bounds.h, sizeof(int));
//gameplay components: equipment, items, buffs, debuffs... //gameplay components: equipment, items, buffs, debuffs...
} }
@@ -62,13 +64,17 @@ void deserializeCharacter(void* buffer, CharacterPacket* packet) {
//location //location
deserialCopy(&buffer, &packet->roomIndex, sizeof(int)); deserialCopy(&buffer, &packet->roomIndex, sizeof(int));
deserialCopy(&buffer, &packet->origin.x, sizeof(double)); deserialCopy(&buffer, &packet->origin.x, sizeof(double));
deserialCopy(&buffer, &packet->origin.y, sizeof(double)); deserialCopy(&buffer, &packet->origin.y, sizeof(double));
deserialCopy(&buffer, &packet->motion.x, sizeof(double)); deserialCopy(&buffer, &packet->motion.x, sizeof(double));
deserialCopy(&buffer, &packet->motion.y, sizeof(double)); deserialCopy(&buffer, &packet->motion.y, sizeof(double));
//stats structure deserialCopy(&buffer, &packet->bounds.x, sizeof(int));
deserializeStatistics(&buffer, &packet->stats); deserialCopy(&buffer, &packet->bounds.y, sizeof(int));
deserialCopy(&buffer, &packet->bounds.w, sizeof(int));
deserialCopy(&buffer, &packet->bounds.h, sizeof(int));
//gameplay components: equipment, items, buffs, debuffs... //gameplay components: equipment, items, buffs, debuffs...
} }
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2013, 2014 /* Copyright: (c) Kayne Ruse 2013-2015
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
@@ -24,8 +24,8 @@
#include "serial_packet_base.hpp" #include "serial_packet_base.hpp"
#include "bounding_box.hpp"
#include "vector2.hpp" #include "vector2.hpp"
#include "statistics.hpp"
struct CharacterPacket : SerialPacketBase { struct CharacterPacket : SerialPacketBase {
//identify the character //identify the character
@@ -40,11 +40,7 @@ struct CharacterPacket : SerialPacketBase {
int roomIndex; int roomIndex;
Vector2 origin; Vector2 origin;
Vector2 motion; Vector2 motion;
BoundingBox bounds;
//gameplay
Statistics stats;
//gameplay components: equipment, items, buffs, debuffs...
}; };
void serializeCharacter(void* buffer, CharacterPacket* packet); void serializeCharacter(void* buffer, CharacterPacket* packet);
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2014 /* Copyright: (c) Kayne Ruse 2013-2015
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2013, 2014 /* Copyright: (c) Kayne Ruse 2013-2015
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
@@ -28,6 +28,7 @@ struct ClientPacket : SerialPacketBase {
int clientIndex; int clientIndex;
int accountIndex; int accountIndex;
char username[PACKET_STRING_SIZE]; char username[PACKET_STRING_SIZE];
//TODO: (3) password, auth token
}; };
void serializeClient(void* buffer, ClientPacket* packet); void serializeClient(void* buffer, ClientPacket* packet);
@@ -0,0 +1,70 @@
/* Copyright: (c) Kayne Ruse 2013-2015
*
* 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 "monster_packet.hpp"
#include "serial_utility.hpp"
void serializeMonster(void* buffer, MonsterPacket* packet) {
serialCopy(&buffer, &packet->type, sizeof(SerialPacketType));
//identify the monster
serialCopy(&buffer, &packet->monsterIndex, sizeof(int));
serialCopy(&buffer, packet->handle, PACKET_STRING_SIZE);
serialCopy(&buffer, packet->avatar, PACKET_STRING_SIZE);
//bounds
serialCopy(&buffer, &packet->bounds.x, sizeof(int));
serialCopy(&buffer, &packet->bounds.y, sizeof(int));
serialCopy(&buffer, &packet->bounds.w, sizeof(int));
serialCopy(&buffer, &packet->bounds.h, sizeof(int));
//location
serialCopy(&buffer, &packet->roomIndex, sizeof(int));
serialCopy(&buffer, &packet->origin.x, sizeof(double));
serialCopy(&buffer, &packet->origin.y, sizeof(double));
serialCopy(&buffer, &packet->motion.x, sizeof(double));
serialCopy(&buffer, &packet->motion.y, sizeof(double));
}
void deserializeMonster(void* buffer, MonsterPacket* packet) {
deserialCopy(&buffer, &packet->type, sizeof(SerialPacketType));
//identify the monster
deserialCopy(&buffer, &packet->monsterIndex, sizeof(int));
deserialCopy(&buffer, packet->handle, PACKET_STRING_SIZE);
deserialCopy(&buffer, packet->avatar, PACKET_STRING_SIZE);
//bounds
deserialCopy(&buffer, &packet->bounds.x, sizeof(int));
deserialCopy(&buffer, &packet->bounds.y, sizeof(int));
deserialCopy(&buffer, &packet->bounds.w, sizeof(int));
deserialCopy(&buffer, &packet->bounds.h, sizeof(int));
//location
deserialCopy(&buffer, &packet->roomIndex, sizeof(int));
deserialCopy(&buffer, &packet->origin.x, sizeof(double));
deserialCopy(&buffer, &packet->origin.y, sizeof(double));
deserialCopy(&buffer, &packet->motion.x, sizeof(double));
deserialCopy(&buffer, &packet->motion.y, sizeof(double));
}
@@ -0,0 +1,46 @@
/* Copyright: (c) Kayne Ruse 2013-2015
*
* 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 MONSTERPACKET_HPP_
#define MONSTERPACKET_HPP_
#include "serial_packet_base.hpp"
#include "bounding_box.hpp"
#include "vector2.hpp"
struct MonsterPacket : SerialPacketBase {
//identify the monster
int monsterIndex;
char handle[PACKET_STRING_SIZE];
char avatar[PACKET_STRING_SIZE];
BoundingBox bounds;
//location
int roomIndex;
Vector2 origin;
Vector2 motion;
};
void serializeMonster(void* buffer, MonsterPacket* packet);
void deserializeMonster(void* buffer, MonsterPacket* packet);
#endif
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2014 /* Copyright: (c) Kayne Ruse 2013-2015
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2013, 2014 /* Copyright: (c) Kayne Ruse 2013-2015
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2014 /* Copyright: (c) Kayne Ruse 2013-2015
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2013, 2014 /* Copyright: (c) Kayne Ruse 2013-2015
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
@@ -1,64 +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 "serial_statistics.hpp"
#include "serial_utility.hpp"
void serializeStatistics(void** buffer, Statistics* stats) {
//integers
serialCopy(buffer, &stats->level, sizeof(int));
serialCopy(buffer, &stats->exp, sizeof(int));
serialCopy(buffer, &stats->maxHP, sizeof(int));
serialCopy(buffer, &stats->health, sizeof(int));
serialCopy(buffer, &stats->maxMP, sizeof(int));
serialCopy(buffer, &stats->mana, sizeof(int));
serialCopy(buffer, &stats->attack, sizeof(int));
serialCopy(buffer, &stats->defence, sizeof(int));
serialCopy(buffer, &stats->intelligence, sizeof(int));
serialCopy(buffer, &stats->resistance, sizeof(int));
serialCopy(buffer, &stats->speed, sizeof(int));
//floats
serialCopy(buffer, &stats->accuracy, sizeof(float));
serialCopy(buffer, &stats->evasion, sizeof(float));
serialCopy(buffer, &stats->luck, sizeof(float));
}
void deserializeStatistics(void** buffer, Statistics* stats) {
//integers
deserialCopy(buffer, &stats->level, sizeof(int));
deserialCopy(buffer, &stats->exp, sizeof(int));
deserialCopy(buffer, &stats->maxHP, sizeof(int));
deserialCopy(buffer, &stats->health, sizeof(int));
deserialCopy(buffer, &stats->maxMP, sizeof(int));
deserialCopy(buffer, &stats->mana, sizeof(int));
deserialCopy(buffer, &stats->attack, sizeof(int));
deserialCopy(buffer, &stats->defence, sizeof(int));
deserialCopy(buffer, &stats->intelligence, sizeof(int));
deserialCopy(buffer, &stats->resistance, sizeof(int));
deserialCopy(buffer, &stats->speed, sizeof(int));
//floats
deserialCopy(buffer, &stats->accuracy, sizeof(float));
deserialCopy(buffer, &stats->evasion, sizeof(float));
deserialCopy(buffer, &stats->luck, sizeof(float));
}
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2014 /* Copyright: (c) Kayne Ruse 2013-2015
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2013, 2014 /* Copyright: (c) Kayne Ruse 2013-2015
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
+13 -1
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2013, 2014 /* Copyright: (c) Kayne Ruse 2013-2015
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
@@ -29,6 +29,12 @@ void serializeText(void* buffer, TextPacket* packet) {
//content //content
serialCopy(&buffer, packet->name, PACKET_STRING_SIZE); serialCopy(&buffer, packet->name, PACKET_STRING_SIZE);
serialCopy(&buffer, packet->text, PACKET_STRING_SIZE); serialCopy(&buffer, packet->text, PACKET_STRING_SIZE);
//location
serialCopy(&buffer, &packet->roomIndex, sizeof(int));
serialCopy(&buffer, &packet->origin.x, sizeof(double));
serialCopy(&buffer, &packet->origin.y, sizeof(double));
serialCopy(&buffer, &packet->range, sizeof(int));
} }
void deserializeText(void* buffer, TextPacket* packet) { void deserializeText(void* buffer, TextPacket* packet) {
@@ -37,4 +43,10 @@ void deserializeText(void* buffer, TextPacket* packet) {
//content //content
deserialCopy(&buffer, packet->name, PACKET_STRING_SIZE); deserialCopy(&buffer, packet->name, PACKET_STRING_SIZE);
deserialCopy(&buffer, packet->text, PACKET_STRING_SIZE); deserialCopy(&buffer, packet->text, PACKET_STRING_SIZE);
//location
deserialCopy(&buffer, &packet->roomIndex, sizeof(int));
deserialCopy(&buffer, &packet->origin.x, sizeof(double));
deserialCopy(&buffer, &packet->origin.y, sizeof(double));
deserialCopy(&buffer, &packet->range, sizeof(int));
} }
+6 -1
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2013, 2014 /* Copyright: (c) Kayne Ruse 2013-2015
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
@@ -24,9 +24,14 @@
#include "serial_packet_base.hpp" #include "serial_packet_base.hpp"
#include "vector2.hpp"
struct TextPacket : SerialPacketBase { struct TextPacket : SerialPacketBase {
char name[PACKET_STRING_SIZE]; char name[PACKET_STRING_SIZE];
char text[PACKET_STRING_SIZE]; char text[PACKET_STRING_SIZE];
int roomIndex;
Vector2 origin;
int range;
}; };
void serializeText(void* buffer, TextPacket* packet); void serializeText(void* buffer, TextPacket* packet);
+7 -5
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2013, 2014 /* Copyright: (c) Kayne Ruse 2013-2015
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
@@ -25,6 +25,7 @@
#include "serial_packet_base.hpp" #include "serial_packet_base.hpp"
#include "character_packet.hpp" #include "character_packet.hpp"
#include "client_packet.hpp" #include "client_packet.hpp"
#include "monster_packet.hpp"
#include "region_packet.hpp" #include "region_packet.hpp"
#include "server_packet.hpp" #include "server_packet.hpp"
#include "text_packet.hpp" #include "text_packet.hpp"
@@ -33,14 +34,15 @@
typedef SerialPacketBase SerialPacket; typedef SerialPacketBase SerialPacket;
//DOCS: NETWORK_VERSION is used to discern compatible servers and clients //DOCS: NETWORK_VERSION is used to discern compatible servers and clients
constexpr int NETWORK_VERSION = 20140909; constexpr int NETWORK_VERSION = 20150304;
union MaxPacket { union MaxPacket {
CharacterPacket a; CharacterPacket a;
ClientPacket b; ClientPacket b;
RegionPacket c; MonsterPacket c;
ServerPacket d; RegionPacket d;
TextPacket e; ServerPacket e;
TextPacket f;
}; };
constexpr int MAX_PACKET_SIZE = sizeof(MaxPacket); constexpr int MAX_PACKET_SIZE = sizeof(MaxPacket);
+94 -17
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2013, 2014 /* Copyright: (c) Kayne Ruse 2013-2015
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
@@ -25,17 +25,20 @@
/* DOCS: The headers indicate what packet type is used for each message /* DOCS: The headers indicate what packet type is used for each message
* different messages under the same header will carry different amounts of * different messages under the same header will carry different amounts of
* valid data, but it will still be carried in that packet's format. * valid data, but it will still be carried in that packet's format.
* FORMAT_* is for internal use, deviding the different format bounds.
*/ */
enum class SerialPacketType { enum class SerialPacketType {
//default: there is something wrong //default: there is something wrong
NONE = 0, NONE,
//------------------------- //-------------------------
//ServerPacket //ServerPacket
// name, player count, version // name, player count, version
//------------------------- //-------------------------
FORMAT_SERVER,
//heartbeat //heartbeat
PING, PING,
PONG, PONG,
@@ -44,61 +47,135 @@ enum class SerialPacketType {
BROADCAST_REQUEST, BROADCAST_REQUEST,
BROADCAST_RESPONSE, BROADCAST_RESPONSE,
FORMAT_END_SERVER,
//------------------------- //-------------------------
//ClientPacket //ClientPacket
// client index, account index, character index // client index, account index, username
//------------------------- //-------------------------
FORMAT_CLIENT,
//Connecting to a server as a client //Connecting to a server as a client
JOIN_REQUEST, JOIN_REQUEST,
JOIN_RESPONSE, JOIN_RESPONSE,
//client requests all information from the server
SYNCHRONIZE,
//disconnect from the server //disconnect from the server
DISCONNECT, DISCONNECT_REQUEST,
DISCONNECT_RESPONSE,
ADMIN_DISCONNECT_FORCED,
//load the account
LOGIN_REQUEST,
LOGIN_RESPONSE,
//unload the account
LOGOUT_REQUEST,
LOGOUT_RESPONSE,
//shut down the server //shut down the server
SHUTDOWN, ADMIN_SHUTDOWN_REQUEST,
FORMAT_END_CLIENT,
//------------------------- //-------------------------
//RegionPacket //RegionPacket
// room index, x, y, raw data // room index, x, y, raw data
//------------------------- //-------------------------
FORMAT_REGION,
//map data //map data
REGION_REQUEST, REGION_REQUEST,
REGION_CONTENT, REGION_CONTENT,
FORMAT_END_REGION,
//------------------------- //-------------------------
//CharacterPacket //CharacterPacket
// handle, avatar, character index, account index, // character index,
// handle, avatar,
// account index (owner),
// room index, origin, motion // room index, origin, motion
// statistics
//------------------------- //-------------------------
//controlling characters FORMAT_CHARACTER,
CHARACTER_NEW,
CHARACTER_DELETE, //full data update
CHARACTER_UPDATE, CHARACTER_UPDATE,
//authentication, character index => character stats //character management
CHARACTER_STATS_REQUEST, CHARACTER_CREATE,
CHARACTER_STATS_RESPONSE, CHARACTER_DELETE,
CHARACTER_LOAD,
CHARACTER_UNLOAD,
//find out info from the server
QUERY_CHARACTER_EXISTS,
QUERY_CHARACTER_STATS,
QUERY_CHARACTER_LOCATION,
//actions taken
CHARACTER_MOVEMENT,
CHARACTER_ATTACK,
CHARACTER_DAMAGE,
//admin control
// ADMIN_SET_CHARACTER_ORIGIN,
FORMAT_END_CHARACTER,
//-------------------------
//MonsterPacket
// monster index,
// handle, avatar
// bounds
// room index, origin, motion
//-------------------------
FORMAT_MONSTER,
//full data update
MONSTER_UPDATE,
//character management
MONSTER_CREATE,
MONSTER_DELETE,
//find out info from the server
QUERY_MONSTER_EXISTS,
QUERY_MONSTER_STATS,
QUERY_MONSTER_LOCATION,
//actions taken
MONSTER_MOVEMENT,
MONSTER_ATTACK,
MONSTER_DAMAGE,
FORMAT_END_MONSTER,
//------------------------- //-------------------------
//TextPacket //TextPacket
// name, text // name, text
//------------------------- //-------------------------
FORMAT_TEXT,
//general speech //general speech
TEXT_BROADCAST, TEXT_BROADCAST,
TEXT_SPEECH,
TEXT_WHISPER,
//rejection/error messages //rejection/error messages
SHUTDOWN_REJECTION,
JOIN_REJECTION, JOIN_REJECTION,
LOGIN_REJECTION,
REGION_REJECTION,
CHARACTER_REJECTION, CHARACTER_REJECTION,
MONSTER_REJECTION,
SHUTDOWN_REJECTION,
QUERY_REJECTION,
FORMAT_END_TEXT,
//------------------------- //-------------------------
//not used //not used
+49 -63
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2014 /* Copyright: (c) Kayne Ruse 2013-2015
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
@@ -24,12 +24,16 @@
//packet types //packet types
#include "character_packet.hpp" #include "character_packet.hpp"
#include "client_packet.hpp" #include "client_packet.hpp"
#include "monster_packet.hpp"
#include "region_packet.hpp" #include "region_packet.hpp"
#include "server_packet.hpp" #include "server_packet.hpp"
#include "text_packet.hpp" #include "text_packet.hpp"
#include <cstring> #include <cstring>
//macros
#define BOUNDS(type, lower, upper) ((type) > (lower) && (type) < (upper))
//raw memory copy //raw memory copy
void serialCopy(void** buffer, void* data, int size) { void serialCopy(void** buffer, void* data, int size) {
memcpy(*buffer, data, size); memcpy(*buffer, data, size);
@@ -45,37 +49,28 @@ void deserialCopy(void** buffer, void* data, int size) {
//main switch functions //main switch functions
void serializePacket(void* buffer, SerialPacketBase* packet) { void serializePacket(void* buffer, SerialPacketBase* packet) {
switch(packet->type) { if (BOUNDS(packet->type, SerialPacketType::FORMAT_SERVER, SerialPacketType::FORMAT_END_SERVER)) {
case SerialPacketType::PING: serializeServer(buffer, static_cast<ServerPacket*>(packet));
case SerialPacketType::PONG: }
case SerialPacketType::BROADCAST_REQUEST:
case SerialPacketType::BROADCAST_RESPONSE: if (BOUNDS(packet->type, SerialPacketType::FORMAT_CLIENT, SerialPacketType::FORMAT_END_CLIENT)) {
serializeServer(buffer, static_cast<ServerPacket*>(packet)); serializeClient(buffer, static_cast<ClientPacket*>(packet));
break; }
case SerialPacketType::JOIN_REQUEST:
case SerialPacketType::JOIN_RESPONSE: if (BOUNDS(packet->type, SerialPacketType::FORMAT_REGION, SerialPacketType::FORMAT_END_REGION)) {
case SerialPacketType::SYNCHRONIZE: serializeRegion(buffer, static_cast<RegionPacket*>(packet));
case SerialPacketType::DISCONNECT: }
case SerialPacketType::SHUTDOWN:
serializeClient(buffer, static_cast<ClientPacket*>(packet)); if (BOUNDS(packet->type, SerialPacketType::FORMAT_CHARACTER, SerialPacketType::FORMAT_END_CHARACTER)) {
break; serializeCharacter(buffer, static_cast<CharacterPacket*>(packet));
case SerialPacketType::REGION_REQUEST: }
case SerialPacketType::REGION_CONTENT:
serializeRegion(buffer, static_cast<RegionPacket*>(packet)); if (BOUNDS(packet->type, SerialPacketType::FORMAT_MONSTER, SerialPacketType::FORMAT_END_MONSTER)) {
break; serializeMonster(buffer, static_cast<MonsterPacket*>(packet));
case SerialPacketType::CHARACTER_NEW: }
case SerialPacketType::CHARACTER_DELETE:
case SerialPacketType::CHARACTER_UPDATE: if (BOUNDS(packet->type, SerialPacketType::FORMAT_TEXT, SerialPacketType::FORMAT_END_TEXT)) {
case SerialPacketType::CHARACTER_STATS_REQUEST: serializeText(buffer, static_cast<TextPacket*>(packet));
case SerialPacketType::CHARACTER_STATS_RESPONSE:
serializeCharacter(buffer, static_cast<CharacterPacket*>(packet));
break;
case SerialPacketType::TEXT_BROADCAST:
case SerialPacketType::JOIN_REJECTION:
case SerialPacketType::SHUTDOWN_REJECTION:
case SerialPacketType::CHARACTER_REJECTION:
serializeText(buffer, static_cast<TextPacket*>(packet));
break;
} }
} }
@@ -84,36 +79,27 @@ void deserializePacket(void* buffer, SerialPacketBase* packet) {
SerialPacketType type; SerialPacketType type;
memcpy(&type, buffer, sizeof(SerialPacketType)); memcpy(&type, buffer, sizeof(SerialPacketType));
switch(type) { if (BOUNDS(type, SerialPacketType::FORMAT_SERVER, SerialPacketType::FORMAT_END_SERVER)) {
case SerialPacketType::PING: deserializeServer(buffer, static_cast<ServerPacket*>(packet));
case SerialPacketType::PONG: }
case SerialPacketType::BROADCAST_REQUEST:
case SerialPacketType::BROADCAST_RESPONSE: if (BOUNDS(type, SerialPacketType::FORMAT_CLIENT, SerialPacketType::FORMAT_END_CLIENT)) {
deserializeServer(buffer, static_cast<ServerPacket*>(packet)); deserializeClient(buffer, static_cast<ClientPacket*>(packet));
break; }
case SerialPacketType::JOIN_REQUEST:
case SerialPacketType::JOIN_RESPONSE: if (BOUNDS(type, SerialPacketType::FORMAT_REGION, SerialPacketType::FORMAT_END_REGION)) {
case SerialPacketType::SYNCHRONIZE: deserializeRegion(buffer, static_cast<RegionPacket*>(packet));
case SerialPacketType::DISCONNECT: }
case SerialPacketType::SHUTDOWN:
deserializeClient(buffer, static_cast<ClientPacket*>(packet)); if (BOUNDS(type, SerialPacketType::FORMAT_CHARACTER, SerialPacketType::FORMAT_END_CHARACTER)) {
break; deserializeCharacter(buffer, static_cast<CharacterPacket*>(packet));
case SerialPacketType::REGION_REQUEST: }
case SerialPacketType::REGION_CONTENT:
deserializeRegion(buffer, static_cast<RegionPacket*>(packet)); if (BOUNDS(type, SerialPacketType::FORMAT_MONSTER, SerialPacketType::FORMAT_END_MONSTER)) {
break; deserializeMonster(buffer, static_cast<MonsterPacket*>(packet));
case SerialPacketType::CHARACTER_NEW: }
case SerialPacketType::CHARACTER_DELETE:
case SerialPacketType::CHARACTER_UPDATE: if (BOUNDS(type, SerialPacketType::FORMAT_TEXT, SerialPacketType::FORMAT_END_TEXT)) {
case SerialPacketType::CHARACTER_STATS_REQUEST: deserializeText(buffer, static_cast<TextPacket*>(packet));
case SerialPacketType::CHARACTER_STATS_RESPONSE:
deserializeCharacter(buffer, static_cast<CharacterPacket*>(packet));
break;
case SerialPacketType::TEXT_BROADCAST:
case SerialPacketType::JOIN_REJECTION:
case SerialPacketType::SHUTDOWN_REJECTION:
case SerialPacketType::CHARACTER_REJECTION:
deserializeText(buffer, static_cast<TextPacket*>(packet));
break;
} }
} }
+1 -1
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2014 /* Copyright: (c) Kayne Ruse 2013-2015
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
+2 -3
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2013, 2014 /* Copyright: (c) Kayne Ruse 2013-2015
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
@@ -26,7 +26,7 @@
#include <stdexcept> #include <stdexcept>
//NOTE: memset() is used before sending a packet to remove old data; you don't want to send sensitive data over the network //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 SerialPacketBase with UDPpacket //NOTE: don't confuse SerialPacketBase with UDPpacket
void UDPNetworkUtility::Open(int port) { void UDPNetworkUtility::Open(int port) {
@@ -140,7 +140,6 @@ int UDPNetworkUtility::SendToAllChannels(void* data, int len) {
return sent; return sent;
} }
//TODO: put a void* and int* parameter list here
int UDPNetworkUtility::Receive() { int UDPNetworkUtility::Receive() {
memset(packet->data, 0, packet->maxlen); memset(packet->data, 0, packet->maxlen);
int ret = SDLNet_UDP_Recv(socket, packet); int ret = SDLNet_UDP_Recv(socket, packet);
+1 -1
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2013, 2014 /* Copyright: (c) Kayne Ruse 2013-2015
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
+1 -1
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2013, 2014 /* Copyright: (c) Kayne Ruse 2013-2015
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
+1 -1
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2013, 2014 /* Copyright: (c) Kayne Ruse 2013-2015
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
+1 -1
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2013, 2014 /* Copyright: (c) Kayne Ruse 2013-2015
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
+1 -1
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2013, 2014 /* Copyright: (c) Kayne Ruse 2013-2015
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
+1 -1
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2013, 2014 /* Copyright: (c) Kayne Ruse 2013-2015
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
+1 -1
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2013, 2014 /* Copyright: (c) Kayne Ruse 2013-2015
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
+1 -1
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2013, 2014 /* Copyright: (c) Kayne Ruse 2013-2015
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
+12 -7
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2013, 2014 /* Copyright: (c) Kayne Ruse 2013-2015
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
@@ -27,13 +27,13 @@
#include <sstream> #include <sstream>
#include <stdexcept> #include <stdexcept>
void ConfigUtility::Load(std::string fname, int argc, char* argv[]) { void ConfigUtility::Load(std::string fname, bool skipMissingFile, int argc, char* argv[]) {
//clear the stored configuration //clear the stored configuration
configMap.clear(); configMap.clear();
//use the default file //use the default file
if (argc < 2) { if (argc < 2) {
configMap = Read(fname); configMap = Read(fname, skipMissingFile);
return; return;
} }
@@ -47,7 +47,9 @@ void ConfigUtility::Load(std::string fname, int argc, char* argv[]) {
for (int i = 1; i < argc; ++i) { for (int i = 1; i < argc; ++i) {
//read from a specified config file //read from a specified config file
if (!strncmp(argv[i], "-config=", 8)) { if (!strncmp(argv[i], "-config=", 8)) {
redirectedFile = Read(argv[i] + 8); //older specified files take precedence
table_t tmp = Read(argv[i] + 8, skipMissingFile);
redirectedFile.insert(tmp.begin(), tmp.end());
redirectUsed = true; redirectUsed = true;
continue; continue;
} }
@@ -73,18 +75,21 @@ void ConfigUtility::Load(std::string fname, int argc, char* argv[]) {
//finally, construct the final config table //finally, construct the final config table
if (!redirectUsed) { if (!redirectUsed) {
redirectedFile = Read(fname); redirectedFile = Read(fname, skipMissingFile);
} }
configMap.insert(cmdLineParams.begin(), cmdLineParams.end()); configMap.insert(cmdLineParams.begin(), cmdLineParams.end());
configMap.insert(redirectedFile.begin(), redirectedFile.end()); configMap.insert(redirectedFile.begin(), redirectedFile.end());
} }
ConfigUtility::table_t ConfigUtility::Read(std::string fname) { ConfigUtility::table_t ConfigUtility::Read(std::string fname, bool skipMissingFile) {
//read in and return this file's data //read in and return this file's data
table_t retTable; table_t retTable;
std::ifstream is(fname); std::ifstream is(fname);
if (!is.is_open()) { if (!is.is_open()) {
if (skipMissingFile) {
return {}; //empty table
}
std::ostringstream os; std::ostringstream os;
os << "Failed to open a config file: " << fname; os << "Failed to open a config file: " << fname;
throw(std::runtime_error( os.str() )); throw(std::runtime_error( os.str() ));
@@ -143,7 +148,7 @@ ConfigUtility::table_t ConfigUtility::Read(std::string fname) {
//load in any subordinate config files //load in any subordinate config files
if (retTable.find("config.next") != retTable.end()) { if (retTable.find("config.next") != retTable.end()) {
table_t subTable = Read(retTable["config.next"]); table_t subTable = Read(retTable["config.next"], skipMissingFile);
retTable.insert(subTable.begin(), subTable.end()); retTable.insert(subTable.begin(), subTable.end());
} }
+4 -7
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2013, 2014 /* Copyright: (c) Kayne Ruse 2013-2015
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
@@ -27,9 +27,9 @@
#include <map> #include <map>
#include <string> #include <string>
class ConfigUtility : public Singleton<ConfigUtility> { class ConfigUtility: public Singleton<ConfigUtility> {
public: public:
void Load(std::string fname, int argc = 0, char* argv[] = nullptr); void Load(std::string fname, bool skipMissingFile = false, int argc = 0, char* argv[] = nullptr);
//convert to a type //convert to a type
std::string& String(std::string); std::string& String(std::string);
@@ -47,10 +47,7 @@ private:
friend Singleton<ConfigUtility>; friend Singleton<ConfigUtility>;
ConfigUtility() = default; table_t Read(std::string fname, bool skipMissingFile);
~ConfigUtility() = default;
table_t Read(std::string fname);
table_t configMap; table_t configMap;
}; };
+1 -1
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2014 /* Copyright: (c) Kayne Ruse 2013-2015
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2014 /* Copyright: (c) Kayne Ruse 2013-2015
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
@@ -19,14 +19,12 @@
* 3. This notice may not be removed or altered from any source * 3. This notice may not be removed or altered from any source
* distribution. * distribution.
*/ */
#include "client_data.hpp" #include "ip_operators.hpp"
int ClientData::IncrementAttempts() { bool operator==(IPaddress lhs, IPaddress rhs) {
lastBeat = Clock::now(); return lhs.host == rhs.host && lhs.port == rhs.port;
return attemptedBeats++;
} }
int ClientData::ResetAttempts() { bool operator!=(IPaddress lhs, IPaddress rhs) {
lastBeat = Clock::now(); return !(lhs == rhs);
return attemptedBeats = 0;
} }
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2014 /* Copyright: (c) Kayne Ruse 2013-2015
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
@@ -19,12 +19,13 @@
* 3. This notice may not be removed or altered from any source * 3. This notice may not be removed or altered from any source
* distribution. * distribution.
*/ */
#ifndef SERIALSTATISTICS_HPP_ #ifndef IPOPERATORS_HPP_
#define SERIALSTATISTICS_HPP_ #define IPOPERATORS_HPP_
#include "statistics.hpp" #include "SDL/SDL_net.h"
void serializeStatistics(void** buffer, Statistics* stats); //these should've come standard
void deserializeStatistics(void** buffer, Statistics* stats); bool operator==(IPaddress lhs, IPaddress rhs);
bool operator!=(IPaddress lhs, IPaddress rhs);
#endif #endif
+1 -1
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2014 /* Copyright: (c) Kayne Ruse 2013-2015
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
+5 -1
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2013, 2014 /* Copyright: (c) Kayne Ruse 2013-2015
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
@@ -92,6 +92,10 @@ public:
return ret; return ret;
} }
//unary operators
Vector2 operator-() { return {-x, -y}; }
//comparison operators
bool operator==(Vector2 v) { return (x == v.x && y == v.y); } bool operator==(Vector2 v) { return (x == v.x && y == v.y); }
bool operator!=(Vector2 v) { return (x != v.x || y != v.y); } bool operator!=(Vector2 v) { return (x != v.x || y != v.y); }
+1 -1
View File
@@ -2,7 +2,7 @@ Future versions (to be determined) may be released under a modified version of t
The current version of Tortuga is released under the zlib license. The current version of Tortuga is released under the zlib license.
Copyright (c) 2013, 2014 Kayne Ruse Copyright (c) 2013-2015 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. 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.
+35
View File
@@ -0,0 +1,35 @@
This is the README for Tortuga's demo build. The source code is available at:
https://github.com/Ratstail91/Tortuga
The current build may have bugs, missing features, bugs masquerading as
features, etc. You can report a bug/feature here:
https://github.com/Ratstail91/Tortuga/issues
Please note that this game requires a functioning server to operate correctly.
Both a game server and game client are included in this package.
-------------------------
Instructions For Setup
-------------------------
1. To create a server, simply run server.exe
(a public server is provided by default)
2. To join a server, your player information must be input into rsc/config.cfg
(NOTE: This process will be streamlined later)
3. To change the config settings, open rsc/config.cfg
4. These settings must be unique for each player:
* client.username
* client.handle
5. There are currently two options for 'client.avatar':
* client.avatar = elliot2.bmp #male
* client.avatar = coa2.bmp #female
6. When you've correctly set these values, run client.exe, and select 'Start'
from the main menu; this displays the list of available servers.
7. Select the name of a server (default is 'Public') and select 'Join'.
8. Welcome to Tortuga, enjoy your stay.
+5 -4
View File
@@ -1,8 +1,9 @@
#for use on Windows: #Windows 7:
#MKDIR=mkdir
#RM=del /y #RM=del /y
#Windows 8.1:
#RM=del /S
OUTDIR=out OUTDIR=out
all: $(OUTDIR) all: $(OUTDIR)
@@ -19,7 +20,7 @@ release: clean all package
#For use on my machine ONLY #For use on my machine ONLY
package: package:
rar a -r -ep Tortuga.rar $(OUTDIR)/*.exe $(OUTDIR)/*.dll rar a -r -ep Tortuga.rar $(OUTDIR)/*.exe $(OUTDIR)/*.dll
rar a -r Tortuga.rar rsc/* copyright.txt rar a -r Tortuga.rar rsc/* copyright.txt instructions.txt
$(OUTDIR): $(OUTDIR):
mkdir $(OUTDIR) mkdir $(OUTDIR)

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